我的mysql表中有3行,例如
company name, tracking type, revenue (columns)
company x, yearly, $100000
company x, monthly, $20000
company x, budget, $30000
我需要将公司名称,年度,月度,预算值显示为单个记录,例如
company x, $100000, $20000, $30000
在这里,我需要将它们与公司名称分组
任何帮助将不胜感激
答案 0 :(得分:0)
您可以使用GROUP BY
& CASE
SELECT company name
, SUM( CASE tracking type WHEN yearly THEN revenue ELSE 0 END)AS yearly
, SUM( CASE tracking type WHEN monthly THEN revenue ELSE 0 END)AS monthly
, SUM( CASE tracking type WHEN budget THEN revenue ELSE 0 END)AS budget
GROUP BY company name