我一直在使用mySQL,但是COUNT函数遇到了问题。我已经尝试删除空格,并且错误仍然存在。
SELECT COUNT(payment) FROM paymentType
GROUP BY payment
ORDER BY COUNT (payment) DESC
LIMIT 1;
我正在尝试在表payment
中找到最常见的paymentType
条目。
答案 0 :(得分:0)
也许是这样?
select *
from (
select payment, count(*) as c from paymentType group by payment
) x
order by c desc
limit 1
答案 1 :(得分:0)
如果您想要最常用的付款方式,那么我想您想要的是:
SELECT payment
FROM paymentType
GROUP BY payment
ORDER BY COUNT(*) DESC
LIMIT 1;
答案 2 :(得分:0)
这将起作用:
SELECT Count(payment),payment FROM paymentType
GROUP BY payment
ORDER BY COUNT DESC
LIMIT 1;
注意:您将在COUNT函数之后获得的列将是一个新列...而且它必须有一个名称-因此SQL自动将其命名为“ count”(请查看上面的最新屏幕截图)。当您在ORDER BY子句中引用此列时,必须使用这个新名称