Re: SELECT, GROUP BY & HAVING problem! On 29 Feb, 11:06, Pavel Lepin <p.le...@ctncorp.com> wrote:
> stockton <simon.stock...@baesystems.com> wrote in
> <cbc1feba-429e-435f-a589-4654ffc07...@u69g2000hse.googlegroups.com>:
>
> >> SELECT ID_2, DAY, COUNT(*) AS COUNT, DISTINCT(MONTH) FROM
> >> `TABLE` GROUP BY `ID_2`, `DAY` HAVING COUNT > 1
>
> > Unfortunately this doesn't work!
>
> Jerry was probably just a bit low on caffeine or something:
>
> SELECT ID_2, DAY, COUNT(DISTINCT MONTH) AS COUNT FROM
> `TABLE` GROUP BY `ID_2`, `DAY` HAVING COUNT > 1;
>
> But really, you should've been able to figure that out
> yourself. That's what the docs are for.
>
> --
> In Soviet Russia, XML documents transform *you*.
Here's a JOIN version for use if the count isn't actually required:
SELECT DISTINCT
i1.id_2,
i1.day
FROM table i1
JOIN table i2 ON i1.id_2 = i2.id_2 AND i1.day = i2.day AND i1.month <>
i2.month |