特定の緯度と経度内にある郵便番号を取得しようとしており、返された郵便番号を使用して、指定されたエリア内のすべての投稿をプルします。緯度と経度の数値は変数ですが、テスト目的では厳密な数値です。誰かがこれを機能させるために正しい方向に私を導くことができますか?
クエリ #1 - Works は投稿を選択します
SELECT user_id, session, zip, price, city, state, post_id, category, shortDesc, fpi
FROM post ORDER BY post.post_id DESC;
クエリ #2 - 地域の郵便番号を選択する
SELECT count(value) as duplicate, value
from (SELECT DISTINCT zipcode as value from zip
WHERE latitude BETWEEN 27.747 AND 28.147
UNION all
SELECT DISTINCT zipcode FROM zip
WHERE longitude BETWEEN -82.657 AND -82.257)
as tbl group by value having count(value) > 1;
サブクエリとしてクエリ
試行済み: 失敗
SELECT user_id, session, zip, price, city, state, post_id, category, shortDesc, fpi
FROM post
WHERE zip = (
SELECT count(value) as duplicate ,value
from (SELECT DISTINCT zipcode as value from zip
WHERE latitude BETWEEN 27.747 AND 28.147
UNION all SELECT DISTINCT zipcode FROM zip
WHERE longitude BETWEEN -82.657 AND -82.257)
as tbl group by value having count(value) > 1)
ORDER BY post.post_id DESC;
エラー #1241 - オペランドには 1 列を含める必要があります
次の試行: 失敗
SELECT user_id, session, zip, price, city, state, post_id, category, shortDesc, fpi
FROM post WHERE zip = (select distinct zipcode from zip
where latitude between 27.747 AND 28.147)
IN ( select distinct zipcode from zip
where longitude between -82.657 AND -82.257);
1242 - サブクエリが複数の行を返す
次の試行: 失敗
SELECT user_id, session, zip, price, city, state, post_id, category, shortDesc, fpi
FROM post
WHERE zip = ANY (
select distinct zipcode from zip
where latitude between 27.747 AND 28.147)
IN ( select distinct zipcode from zip
where longitude between -82.657 AND -82.257);
1064 - SQL 構文にエラーがあります。