count(*)列到数据的右边?

时间:2013-06-05 09:49:43

标签: mysql database count

每当我使用MySQL数据库中的count来提取数据时,它总是将count列放在最左边的列中。

e.g。

查询:select count(*),name from db.db group by name order by name desc

得到:

count(*) | name
-----------------
23       | Andy
65       | Bob
12       | Chris

有没有办法让它像这样?:

name | count(*)
-----------------
Andy | 23
Bob  | 65
Chris| 12

7 个答案:

答案 0 :(得分:1)

您只需将您的点数和列名反转为具有不同的顺序

select name, count(*) from db.db group by name order by name desc

您将在SELECT查询中为列提供的顺序将是返回列的顺序

答案 1 :(得分:0)

只需使用

select name, count(*) from db.db group by name order by name desc

答案 2 :(得分:0)

只需在选择

中切换名称和计数
select name,count(*) from db.db group by name order by name desc

答案 3 :(得分:0)

试试这个:

SELECT name, COUNT(*) FROM db.db GROUP BY name ORDER BY name DESC

答案 4 :(得分:0)

只需像这样更改输出序列:

query: select name,count(*) from db.db group by name order by name desc

答案 5 :(得分:0)

select name,count(*) as cnt from db.db group by name order by name desc

答案 6 :(得分:0)

尝试:

SELECT NAME,COUNT(*) AS cnt FROM db.db GROUP BY NAME ORDER BY NAME DESC