数据查询实战1
订单头表order
id |
order_id |
sku |
num |
|
|
|
|
订单行表order_item
id |
order_sn |
amount(总价) |
create_time |
buyer_name |
|
|
|
|
|
1) 请查询双十一晚上八点到十一点期间,商品sku为‘L123’的商品的售卖数量。
select sum(item.num) from order_item item where sku = ‘L123’ and order_id in (select id from order where create_time between 2021-11-11 20:00:00 and 2021-11-11 23:00:00)
2) 请查询双十一晚上八点到十一点期间,购买过sku为‘L123’商品的、且消费金额大于2000的用户。
select buyer_name from order where (create_time between 2021-11-11 20:00:00 and 2021-11-11 23:00:00) and amount>2000 and id in (select id from order_item where sku = ‘L123’)