您能帮我吗,我的查询有问题。 我有像波纹管这样的数据:
+------------+---------+-----+
| Date | Prod_ID | Qty |
+------------+---------+-----+
| 01/02/2018 | Pencil | 2 |
| 01/02/2018 | pencil | 3 |
| 01/02/2018 | pencil | 4 |
| 01/02/2018 | book | 5 |
| 01/02/2018 | ruller | 1 |
+------------+---------+-----+
但我的结果是波纹管
+------------+---------+-----+
| Date | Prod_ID | Qty |
+------------+---------+-----+
| 01/02/2018 | 5 | 15 |
+------------+---------+-----+
我需要下面的结果
+------------+---------+-----+
| Date | Prod_ID | Qty |
+------------+---------+-----+
| 01/02/2018 | 3 | 15 |
+------------+---------+-----+
使用我的查询脚本
select "date",
Prod_ID,
Qty,
from data
group by "date",
Prod_ID,
Qty,
order by "date";
谢谢
答案 0 :(得分:2)
您可以尝试以下操作:
select "date",
Count(Distinct Prod_ID) as total_product_count,
Sum(Qty) as qty
from
data
group by
"date"
order by "date";