本文介绍了销售汇总的 SQL 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮我解决这个问题
select pName,Price, (Price*Quantity) as SalesValues from saleslog where
BillDate='12-10-2010' and pGroup=15 group by pname, Quantity, Price;
此查询旨在根据日期显示销售摘要,但显示重复的产品名称.
This query is intended to show sales summary according to date but it is showing duplicate Products Name.
上述查询的输出
MAK 2 T OIL 5LTR. 635 3175
MAK 2 T OIL 5LTR. 635 6350
MAK ELITE 3LTR 422 6330
MAK ELITE 3LTR 422 8440
SYSTEM PURGE 305 6100
SYSTEM PURGE 305 15250
你可以看到重复的产品名称,但我想要根据产品名称的销售摘要.
as you can see repeated product name but i want sale summary according to Product Name.
谢谢…………
推荐答案
SELECT pName, SUM(Price * Quantity) AS SalesValues
FROM saleslog
WHERE BillDate = '12-10-2010'
AND pGroup = 15
GROUP BY
pname
我删除了 Price
因为它可以(可能)变化并且不清楚输出哪个.
I removed Price
since it can (possibly) vary and it's not clear which one to output.
如果价格不变,请使用:
If the price does not vary, use this:
SELECT pName, MIN(price), SUM(Price * Quantity) AS SalesValues
FROM saleslog
WHERE BillDate = '12-10-2010'
AND pGroup = 15
GROUP BY
pname
这篇关于销售汇总的 SQL 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!