如何重新排列结果中的列? MySQL工作台

问题描述

新手在这里

我使用以下代码获取每年每月每个用户总数的结果。

select 
    count(*) as 'new users',year(joined_at) as year,month(joined_at) as month 
from users
group by year,month
order by year asc,month asc; 

结果按顺序显示在表格中

 new users | year | month

如何使结果显示

Year | Month | New users

解决方法

此查询将产生您要求的结果,年份| |新用户。

您需要做的就是重新排列select语句中的列。它们按照您添加到查询中的顺序显示。

select 
 year(joined_at) as year,month(joined_at) as month,count(*) as 'new users'
from users
group by year,month
order by year asc,month asc;