我的输入如下。
+----+-------+---------+----------+----+----+
| A | B | C | D | E | F |
+----+-------+---------+----------+----+----+
| 3 | 32447 | 168531 | 2/2/2017 | 10 | 20 |
| 4 | 32447 | 168531 | 2/3/2017 | 10 | 20 |
| 14 | 32447 | 168531 | 2/6/2017 | 10 | 20 |
| 14 | 32447 | 168531 | 2/6/2017 | 10 | 20 |
| 12 | 32447 | 168531 | 2/7/2017 | 10 | 20 |
| 12 | 32447 | 168531 | 2/7/2017 | 10 | 20 |
| 12 | 32447 | 168531 | 2/7/2017 | 10 | 20 |
| 46 | 32447 | 168531 | 2/8/2017 | 10 | 20 |
| 46 | 32447 | 168531 | 2/8/2017 | 10 | 20 |
| 46 | 32447 | 168531 | 2/8/2017 | 10 | 20 |
| 85 | 32447 | 168531 | 2/9/2017 | 10 | 20 |
| 85 | 32447 | 168531 | 2/9/2017 | 10 | 20 |
| 85 | 32447 | 168531 | 2/9/2017 | 10 | 20 |
+----+-------+---------+----------+----+----+
我的预期输出如
+----+-------+--------+----------+----+----+
| A | B | C | D | E | F |
+----+-------+--------+----------+----+----+
| 3 | 32447 | 168531 | 2/2/2017 | 10 | 20 |
| 4 | 32447 | 168531 | 2/3/2017 | 10 | 20 |
| 14 | 32447 | 168531 | 2/6/2017 | 20 | 40 |
| 12 | 32447 | 168531 | 2/7/2017 | 30 | 60 |
| 46 | 32447 | 168531 | 2/8/2017 | 30 | 60 |
| 85 | 32447 | 168531 | 2/9/2017 | 30 | 60 |
+----+-------+--------+----------+----+----+
我正在使用像
这样的查询select b,c,d,sum(e),sum(f)
group by b,c,d
如何获得没有MAX概念的列值?感谢。
答案 0 :(得分:0)
select max(a),b,c,d,sum(e),sum(f)
group by b,c,d
答案 1 :(得分:0)
将SUM
函数与GROUP BY
子句一起使用。
<强>查询强>
select a, b, c, d, sum(e) e, sum(f) f
from your_table_name
group by a, b, c, d;
答案 2 :(得分:0)
select a,b,c,d,sum(e)e,sum(f)f FROM Table_Name
group by a,b,c,d
答案 3 :(得分:0)
试试这个..希望这对你有用
select a,b,c,d,sum(e),sum(f) FROM yourtable out_TB
WHERE A=(SELECT TOP 1 in_TA.A FROM yourtable in_TA WHERE in_TA.A=out_TB.A ORDER BY in_TA.A DESC)
group by a,b,c,d
答案 4 :(得分:0)
使用distinct:
SELECT DISTINCT r.* FROM
(
...your query here...
) r
ORDER BY 1
/