⽇期范围内商品销售额排⾏榜的SQL语句编写
萘哌地尔片
⼀:涉及订单表,订单详细表
SQL:
SELECT productName '商品名称',SUM(price*number) '销售总额'
FROM t_orderdetail
WHERE orderID IN (SELECT id
FROM t_order
WHERE DATE(createdate)
BETWEEN '2014-01-01'
AND '2014-01-31')
GROUP BY productID
ORDER BY SUM(price*number) DESC
中变社区
LIMIT 0,10
深圳锦绣中华查询结果:
⼆:涉及订单表,订单详细表,商品表
功能:从商品表中获取商品相关信息, 从详细表中获取商品销售总额, 时间范围由订单表中的⽇期限制;按商品分组,按商品销售额降序排列,查询前⼗名。
SQL:
留学背景提升SELECT p.`name` 名称,p.`introduce` 简介,SUM(o.price*o.number) 总额
司马牛之叹FROM t_product p
JOIN t_orderdetail o
ON p.`id` = o.`productID`
行车记录仪十大品牌derID IN (SELECT t_order.id
FROM t_order
WHERE DATE(atedate)
BETWEEN '2014-01-01' AND '2014-01-31')
GROUP BY o.productID
色子玩法ORDER BY SUM(o.price*o.number) DESC
LIMIT 0,10
查询结果:
三:表
T_product:
T_order:
烤燕麦饼
T_orderdetail:
四:页⾯显⽰排⾏