how to count specific row where variable can be more then one
how i can write the query ex;-
select count(id) where animal = rat , elephant ,cat, mouse
how i can do this in mysql.开发者_如何学C ex means count the row where animal = rat ,elephant, cat ,mouse
This will return a single COUNT
for all matching animals:
SELECT COUNT(id)
WHERE animal IN ('rat', 'elephant' , 'cat', 'mouse')
This will count animal-wise:
SELECT animal, COUNT(id)
WHERE animal IN ('rat', 'elephant' , 'cat', 'mouse')
GROUP BY
animal
i. e. will return how many rats, elephants etc. are there in the table.
This is almost correct. You write
WHERE var IN (value1, value2, ..., valueN)
This is equivalent with
WHERE var = value1 OR var = value2 OR var = .... OR var = valueN
精彩评论