查询如下:
SELECT TBL.ID, TBL.CODE1, TBL.CODE2, TBL.CODE3, TBL.CODE4, TBL.QTY
FROM DB.TBL TBL
GROUP BY TBL.ID, TBL.CODE1, TBL.CODE2, TBL.CODE3, TBL.CODE4, TBL.QTY
这将返回如下数据:
ID | CODE1 | CODE2 | CODE3 | CODE4 | QTY
--------+-----------+-----------+-----------+-----------+----------
1 | H1 | G2 | R3 | MM | 5
2 | F1 | E2 | J3 | SS | 2
3 | H1 | G2 | R3 | LL | 8
4 | C1 | I2 | O3 | PP | 6
5 | F1 | E2 | J3 | EE | 1
如何在行之间的QTY
,CODE1
和CODE2
列相同的情况下添加列CODE3
的总和?
ID | ... | QTY | SUM
--------+-------+-------+----------
1 | ... | 5 | 13
2 | ... | 2 | 3
3 | ... | 8 | 13
4 | ... | 6 | 6
5 | ... | 1 | 3
类似以下内容:
SUM(CASE WHEN TBL.CODE1=TBL.CODE1 AND TBL.CODE2=TBL.CODE2 AND TBL.CODE3=TBL.CODE3 THEN TBL.QTY ELSE 0 END)
答案 0 :(得分:2)
您可以使用窗口功能:
public void UsageExample()
{
Console.WriteLine(SHA.GenerateSHA512String("abc"));
//returns DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA20A9EEEE64B55D39A2192992A274FC1A836BA3C23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F
}