Answer the question
In order to leave comments, you need to log in
How to count the number of unique records?
There is a table
CREATE TABLE `example` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`cid` BIGINT(20) NOT NULL,
`date_time` DATETIME NOT NULL,
PRIMARY KEY (`id`),
)
SELECT COUNT(DISTINCT сid)
FROM example
WHERE date_time > '2015-10-01 00:00:00'
Answer the question
In order to leave comments, you need to log in
task is not entirely clear, but
SELECT t.cid, t.date_time, t2.cnt
FROM example t
LEFT JOIN
(SELECT cid, COUNT(id) as cnt FROM example GROUP BY cid) t2 ON (t2.cid = t.cid)
WHERE date_time > '2015-10-01 00:00:00'
-- and t2.cnt = 1 -- только уникальные
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question