【问题标题】:How can i rearrange my columns in the results? MySQL Workbench如何重新排列结果中的列? MySQL 工作台
【发布时间】:2020-11-11 09:27:15
【问题描述】:

这里是新手。

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

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 first_visible_column, second_visible_column, third_visible_column FROM table_name

标签: mysql workbench


【解决方案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; 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-25
    • 2021-12-28
    • 2023-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-10
    相关资源
    最近更新 更多