0
我正在執行兩個查詢,第一個用於內部聯接以從表 中獲取數據,第二個組通過查詢獲得總和。如何通過select語句執行與另一個組的聯接查詢
但有什麼辦法可以在一個查詢中執行兩個查詢嗎?
首先查詢:
SELECT e.name,Value,address FROM table1 e JOIN table2 p ON p.name = e.name;
+--------+---------+------+----+
| name | Value | address |
+--------+---------+------+----+
| name1 | 124 | address1 |
| name2 | 12 | address2 |
| name3 | 123 | address3 |
| name2 | 15 | address2 |
+-------------+---------+------+
第二個查詢:
SELECT name , SUM(Value) Total FROM table1 GROUP BY name;
+-------------+-------+
| name | Total |
+-------------+-------+
| name3 | 123 |
| name2 | 27 |
| name1 | 124 |
+-------------+-------+
和我要的是對每名之列
+-------------+------------+
| name | sum | address |
+-------------+------------+
| name1 | 124 | address1 |
| name2 | 12 | address2 |
| name3 | 123 | address3 |
+-------------+------------+
是SQLserver還是MYSQL – TheGameiswar