在sql查询输出中更改单元格的显示名称

时间:2018-02-21 16:36:23

标签: mysql sql

我正在尝试运行查询以从表中获取结果并更改"显示名称"输出变量。该查询用于图表,我需要在图表中显示可理解的值。这是我正在使用的代码。最后两行是问题所在。我需要重命名显示名称。

感谢任何帮助

SELECT table.date, table.concept, table.avg, table.avg90, table.avg30, table.avg7

FROM table
WHERE table.date
IN (

SELECT MAX( DATE ) 
FROM table
GROUP BY table.concept
)
AND table.concept in  ('h2h_globalism','h2h_populism')
WHERE 'h2h_globalism' = 'Globalism')
WHERE 'h2h_populism' = 'Populism')

2 个答案:

答案 0 :(得分:0)

您必须添加别名。例如:

SELECT table.date as DATE, table.concept as CONCEPT, table.avg as AVG, table.avg90 as AVG90, table.avg30 as AVG30, table.avg7 as AVG7

FROM table
WHERE table.date
IN (

SELECT MAX( DATE ) 
FROM table
GROUP BY table.concept
)
AND table.concept in  ('h2h_globalism','h2h_populism')
WHERE 'h2h_globalism' = 'Globalism')
WHERE 'h2h_populism' = 'Populism')

答案 1 :(得分:0)

听起来你需要替换这个位

SELECT table.date, table.concept, table.avg, table.avg90, table.avg30, table.avg7

以下内容。

SELECT table.date, 
Case when table.concept = 'h2h_globalism' then 'globalism' else 'populism' end as concept,
 table.avg, table.avg90, table.avg30, table.avg7