I have a table similar to the following
I would like to count the total number of unique sequence
numbers for a given user
and/or date
. I have been attempting to do this by using DISTINCT
in the following manner:
SELECT COUNT(DISTINCT sequence) FROM table WHERE date=2020-06-29 // should return 2
The WHERE
seems to be causing some issues because the response is 0. Do I need to do this using sub-queries instead?
Wrap your date with quote ( '
) SELECT COUNT(DISTINCT sequence) FROM table WHERE date='2020-06-29'
may be this query is what you're looking for
SELECT COUNT(DISTINCT sequence) FROM table WHERE date = '2020-06-29'
or if you are not using mysql console may be you're using an editor try to save the date in the particular variable as a string thereafter call it
like:
date = '2020-06-29'
SELECT COUNT(DISTINCT sequence) FROM table WHERE date = date
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.