1

How can I do multiple counts for the same field in 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
0

2 Answers 2

3
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.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah that work, thanks. I was sure I was doing something silly :)
1

Remove extra comma before FROM

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.