Thanks, was aware, but the SQL was indeed wrong as posted and should have
brackets around the 2 or conditions.
Corrected now.
Could I post a little demo SQLite file? Not sure now if this is allowed as
an attachment.
That would be easiest.

RBS

On Sun, Nov 25, 2018 at 12:52 AM Igor Tandetnik <i...@tandetnik.org> wrote:

> On 11/24/2018 7:44 PM, Bart Smissaert wrote:
> > The very much simplified example works fine, but my real SQL is a bit
> more
> > complex:
> >
> > select gp_name, count(*) as pat_count,
> > sum(emis_number in(select emis_number from diabetics)) as diab_count from
> > patients
> > where emis_number in(select emis_number from diabetics)
> > and emis_number in(select emis_number from on_non_insulin)
> > or emis_number in(select emis_number from on_insulin)
> > group by gp_name
> > order by pat_count asc
>
> Just in case you are not aware, AND has higher precedence than OR. Your
> query does ( (Diabetics AND Non-Insulin) OR Insulin ) as opposed to (
> Diabetics AND (Non-Insulin OR Insulin) ). Apologies if you knew that and
> really meant the former.
>
> > The above SQL works, but gives too low counts for diab_count .
>
> Show sample data, the result you expect, and the result you observe
> instead.
> --
> Igor Tandetnik
>
>
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to