首页 > 试题广场 >

表A:用户信息表USERINFO,字段:用户编号(USERI

[问答题]
表A:用户信息表USERINFO,字段:用户编号(USERID)、用户姓名(CUSTNAME)、性别(GENDER)、身份证号(IDNO)
表B:消费订单表ORDERINFO,字段:订单编号(ORDERID)、用户编号(USERID)、商品编号(GOODSID)、订单创建时间(CREATETIME)
查询姓名为张三用户的消费订单信息且按照订单创建时间倒叙排序
select * from orderinfo where userid in (select userid from userinfo where custname ='张三') order by createtime desc
发表于 2019-03-15 11:39:04 回复(0)
我的答案是:select * from order info where user id in (select user id from user info where cust name ='张三') order by create time desc
发表于 2019-04-24 14:24:57 回复(0)
select b.orderid,b.goodsid,b.createtime from a,b where a.userid=b.userid and a.custname ='张三' order by b.cratetime
发表于 2019-03-08 22:04:19 回复(0)
dictA=[{'userinfo':'A','userid':'A1','username':'张三','usergender':'A3','idno':'A4'},
       {'userinfo':'B','userid':'B1','username':'B2','usergender':'B3','idno':'B4'},
       {'userinfo':'C','userid':'C1','username':'C2','usergender':'C3','idno':'C4'}]
dictB=[{'orderinfo':'a','orderid':'a1','userid':'A1','goodid':'a3','createtime':'4'},
       {'orderinfo':'b','orderid':'b1','userid':'A1','goodid':'b3','createtime':'5'},
       {'orderinfo':'b','orderid':'b1','userid':'B1','goodid':'b3','createtime':'6'}]
USERID = ''
lst=[]
for item in dictA:
    if item.get('username')=='张三':
         USERID=item.get('userid')
print(USERID)

for item in dictB:
    if item.get('userid')==str(USERID):
        lst.append(item)
print(lst)

res=sorted(lst,key=lambda x:x['createtime'],reverse=True)
print(res)

发表于 2021-06-30 21:48:03 回复(0)
查出来的 userid 没有去重!!!!!
select * from 
userinfo u left join orderinfo o 
on u.userid = o.userid 
where custname = '张三' 
order by createtime
编辑于 2019-12-09 10:09:55 回复(0)