的MySQL 我有一些带有10多行的单组,有2个相同的字符串(日期和参考号) Mysql数据库:
id name qty ref weight date
1 name1 2 x1 22 2011-01-01
2 name2 3 x1 13 2011-01-01
3 name3 4 x2 10 2021-02-02
4 name4 5 x2 15 2021-02-02
请你帮忙,我怎样才能获得单一的结果,并总结各组的数量和重量,如下:
ref weight qty date
x1 35 5 2011-01-01
x2 25 9 2021-02-02
我尝试了不同,但在这种情况下,不能得到总和。
答案 0 :(得分:1)
您只需使用The SQL GROUP BY Statement:
SELECT ref, sum(weight) as weight,sum(qty) as qty, date
FROM tablename GROUP BY date
答案 1 :(得分:0)
这对你有用。
SELECT sum(weight),sum(qty) from tablename GROUP BY date
答案 2 :(得分:0)
使用以下查询:
SELECT ref, sim(weight) as weight, sum(qty) as qty, date
FROM table_name
GROUP BY CONCAT(ref, date)