mysql error-count不存在,错误1630

avwztpqn  于 2021-06-17  发布在  Mysql
关注(0)|答案(3)|浏览(334)

我一直在mysql中工作,我一直在使用count函数。我已经尝试删除空格,错误仍然存在。

SELECT COUNT(payment) FROM paymentType
GROUP BY payment 
ORDER BY  COUNT (payment) DESC
LIMIT 1;

我想找到最常见的 payment 表中的条目 paymentType .

6rqinv9w

6rqinv9w1#

这将起作用:

SELECT Count(payment),payment FROM paymentType
GROUP BY payment 
ORDER BY  COUNT DESC
LIMIT 1;

注意:在count函数之后得到的列将是一个新列…它必须有一个名称–因此sql会自动将其命名为“count”(查看上面最新的屏幕截图)。在order by子句中引用此列时,必须使用此新名称

pzfprimi

pzfprimi2#

如果你想要最普通的付款方式,那么我认为你想要:

SELECT payment
FROM paymentType
GROUP BY payment 
ORDER BY COUNT(*) DESC
LIMIT 1;
dvtswwa3

dvtswwa33#

像这样的可能?

select *
from (
  select payment, count(*) as c from paymentType group by payment
) x
order by c desc
limit 1

相关问题