SELECT DISTINCT "Users"."id" , "Users".name,
"Users"."surname", "Users"."gender",
"Users"."dob", "Searches"."start_date"
FROM "Users"
LEFT JOIN "Searches" ON "Users"."id" = "Searches"."user_id"
WHERE (SQRT(POW(69.1 * ("Users"."latitude" - 45.465454), 2) + POW(69.1 * (9.186515999999983 - "Users"."longitude") * COS("Users"."latitude"/57.3), 2))) < 20
AND "Users"."status" = true
AND "Users"."id" != 18
AND "Searches"."activity" = \'clubbing\'
AND "Users"."gender" = \'m\'
AND "Users"."age" BETWEEN 18 AND 30
ORDER BY ABS("Searches"."start_date" - date \'2016-07-07\')
因爲某些原因上面的查詢將返回以下錯誤:Postgres的DISTINCT查詢問題
for SELECT DISTINCT, ORDER BY expressions must appear in select list
我只想要返回唯一用戶,但我真的不知道什麼是錯。
感謝您的幫助
錯誤信息中你不明白的是什麼? –
@GordonLinoff我不知道該怎麼做,因爲我沒有看到任何錯誤。 start_date已經在SELECT列表 – Anonymous
中。 。它可能需要整個表達式在'select'中。 –