-8

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

例如

询问: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
4

7 回答 7

1

您只需要反转您的计数和您的名称即可获得不同的顺序

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

您将在 SELECT 查询中给列的顺序将是返回列的顺序

于 2013-06-05T09:51:34.527 回答
0

只需使用

select name, count(*) from db.db group by name order by name desc
于 2013-06-05T09:50:59.650 回答
0

只需切换名称并在您的选择中计数

select name,count(*) from db.db group by name order by name desc
于 2013-06-05T09:51:23.863 回答
0

试试这个:

SELECT name, COUNT(*) FROM db.db GROUP BY name ORDER BY name DESC
于 2013-06-05T09:52:36.137 回答
0

只需像这样更改您的输出顺序:

query: select name,count(*) from db.db group by name order by name desc
于 2013-06-05T09:52:41.997 回答
0
select name,count(*) as cnt from db.db group by name order by name desc
于 2013-06-05T09:53:56.577 回答
0

尝试:

SELECT NAME,COUNT(*) AS cnt FROM db.db GROUP BY NAME ORDER BY NAME DESC
于 2013-06-05T09:58:56.793 回答