简体   繁体   English

单个mysql查询中的多个计数

[英]multiple counts in single mysql query

How can I do multiple counts for the same field in mysql? 如何在mysql中对同一个字段进行多次计数? The code below for a single count works fine 单个计数的下面的代码工作正常

SELECT fruit, COUNT(DISTINCT site) AS `apple` FROM grocery where fruit like '%06201%'

However, when I have tried this but I get syntax error 但是,当我尝试这个但我得到语法错误

SELECT
    SUM(fruit like '%06201%') AS `apple`,
    SUM(fruit like '%02206%') AS `pears`,
FROM grocery
SELECT
    SUM(fruit like '%06201%') AS `apple`,
    SUM(fruit like '%02206%') AS `pears`,
                                        ^
                                        here
FROM grocery

You have two commata, but you only need one. 你有两个commata,但你只需要一个。

Remove extra comma before FROM FROM之前删除额外的逗号

SELECT
    SUM(fruit like '%06201%') AS `apple`,
    SUM(fruit like '%02206%') AS `pears`
FROM grocery

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM