我创建了这样的表:
sim_mcc_mnc January February March ....
232-10 1234 4321 5678 (these numbers are number of records)
手动命名每一列:
SELECT
sim_mcc_mnc,
sum(year(time_utc)=2013 AND month(time_utc)=1) as 'January 2013',
sum(year(time_utc)=2013 AND month(time_utc)=2) as 'February 2013',
sum(year(time_utc)=2013 AND month(time_utc)=3) as 'March 2013',
sum(year(time_utc)=2013 AND month(time_utc)=4) as 'April 2013',
...
...
...
FROM
table
where
sim_mcc_mnc like '232-%' OR
sim_mcc_mnc is null
GROUP BY
sim_mcc_mnc
;
我的问题是。是否有可能自动命名这些列?我尝试使用CONCAT
,但在我看来,AS
之后你不能使用任何函数。
还有其他可能吗?
答案 0 :(得分:0)
我不知道你要用以下几行做什么...
sum(year(time_utc)=2013 AND month(time_utc)=1) as 'January 2013',
这将返回匹配的行数,而不是值的总和......
要回答您的问题,您有两种可能性: