Trouble with SQLite SQL Query -
this question exact duplicate of:
- sqlite - clause & udfs 4 answers
i'm trying run following query in sqlite 3:
select *, distance(latitude, longitude, ?, ?) "distance" "country" "id" not ? having "distance" <= ? order "distance" asc;
but following error:
sqlstate[hy000]: general error: 1 group clause required before having
i don't understand why sqlite wants me group results, still tried following:
select *, distance(latitude, longitude, ?, ?) "distance" "country" "id" not ? group "id" having "distance" <= ? order "distance" asc;
and tried this:
select *, distance(latitude, longitude, ?, ?) "distance" "country" "id" not ? group "distance" having "distance" <= ? order "distance" asc;
no errors, records returned (even having "distance" > ?
). tried doing:
select *, distance(latitude, longitude, ?, ?) "distance" "country" "id" not ? , "distance" <= ? order "distance" asc;
same output, records returned. i've double checked - distance being correctly calculated... i've no idea what's wrong query, can me out?
you can't specify having
clause without having specified group by
clause. use:
select *, distance(latitude, longitude, ?, ?) dist country c c.id not ? , distance(c.latitude, c.longitude, ?, ?) <= ? order dist;
if don't want call distance more once, can use subquery:
select x.* (select c.*, distance(latitude, longitude, ?, ?) dist country c c.id not ?) x x.dist <= ? order dist;
Comments
Post a Comment