Trouble with SQLite SQL Query -


this question exact duplicate of:

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

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -