我有两个表 tabeleA 和 tableB..
在表 A 中,我有列(名称) 在表 B 中,我有列(金额)
表A:
cat_id cat_name
1 Man
2 Women
3 General
Run Code Online (Sandbox Code Playgroud)
表B:
cat_id cat_price
1 12
1 18
1 34
1 23
2 21
3 31
1 21
3 56
Run Code Online (Sandbox Code Playgroud)
现在,在这两个表中,我有名称和价格,它们通过 cat_id 链接。
现在我想显示该特定名称的名称和价格,并且价格应该是特定类别的总价......
像这样的东西:
表新:
cat_name cat_price
Man 104
Woman 21
General 87
Run Code Online (Sandbox Code Playgroud)
请帮忙..谢谢...
SELECT
tA.cat_name, SUM(tB.cat_price) AS price
FROM TableA tA
INNER JOIN TableB tB
ON tA.cat_id=tB.cat_id
GROUP BY tA.cat_id
Run Code Online (Sandbox Code Playgroud)