0

新手来了

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

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
4

1 回答 1

1

此查询将产生您需要的结果,Year | 月 |新用户。

您需要做的就是重新排列您的 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; 
于 2020-11-11T09:31:29.060 回答