i've got 2 tables.
'order details' orderid | quantity | unitprice | productid 1002 | 19 | 17 | 824 1002 | 5 | 15 | 285 1003 | 7 | 6 | 543 1004 | 12 | 11 | 205
'orders' orderid | customerid 1002 | 224 1003 | 348 1005 | 224
i have id of customer has bought maximum of products. can see 1 customer can have not 1 orderid
i think should works fine:
select top 1 customerid ( select customerid, sum(od.quantity) sum orders o inner join order_details od on o.orderid = od.orderid group customerid order sum desc)
check tables name
Comments
Post a Comment