SQL可能子查询
整天我正在考虑如何从单个表中获取单个查询的结果。我问你,如果我能得到想要的结果,就像我已经附上的实例。SQL可能子查询
campo1 campo2 campo3 A A1 10
A A1 20
A A2 5
B B1 50
B B2 60
C C1 80
C C2 90
C C2 100
I want to get
SUM of campo3 GROUPED BY campo1
SUM of campo3 GROUPED BY campo2
in this case I want to get this result;
A= 35
B= 110
C= 270
A1=30
A2=5
B1=50
B2=60
C1=80
C2=190
回答:
试试这个:
Select Campo1,null, Sum(Campo3) From Table Group By Campo1
Union All
Select null, Campo2, Sum(Campo3) From Table
Group By Campo2
以上是 SQL可能子查询 的全部内容, 来源链接: utcz.com/qa/258717.html