2012-05-05 7 views
2

私は完全に実行しているこのクエリを持っていますこのSQLサブクエリの書き方は?

このクエリから私は私の場所からすべてのレストラン3 KMを選択していますこれは私の最初のテーブルです。

SELECT foodjoint_id,foodjoint_name,open_hours,cont_no,address_line,city (3959 * acos(cos(radians('".$userLatitude."')) * cos(radians(foodjoint_latitude)) * cos(radians(foodjoint_longitude) - radians('".$userLongitude."')) + sin(radians('".$userLatitude."')) * sin(radians(foodjoint_latitude)))) AS distance 
FROM provider_food_joints 
HAVING distance < '3' ORDER BY distance LIMIT 0 , 20 

しかし、私はこの3Kmの中にあるそれらの食品接合部からAVG評価を選択する必要があります。

問い合わせも完璧に実行されている:

select AVG(customer_ratings) from customer_review where foodjoint_id=".$foodjoint_id 

が、私はこれらすべての食品のジョイントとその評価AVGを選択することができ、それを通してこの2つのクエリを追加する必要があります。

+3

は、私は** ** B **その後、中括弧から始まる5番目のボタンをクリックし、クエリを強調表示します:-)のstackoverflowへようこそ** ... –

+0

追加の文言として、整数の周りに引用符を使用しないでください(距離の場合は '3')。あなたや他の誰かが戻ってクエリを参照すると、誤解を招くことがあります。 –

答えて

1

だけでサブクエリを配置し、あなたの結果を取得します:

`SELECT foodjoint_id,foodjoint_name,open_hours,cont_no,address_line,city (3959 * acos(cos(radians('".$userLatitude."')) * cos(radians(foodjoint_latitude)) * cos(radians(foodjoint_longitude) - radians('".$userLongitude."')) + sin(radians('".$userLatitude."')) * sin(radians(foodjoint_latitude)))) AS distance, 

(select AVG(customer_ratings) from customer_review where customer_review.foodjoint_id=provider_food_joints.foodjoint_id) as Customer_Reviews 

FROM provider_food_joints 

HAVING distance < '3' ORDER BY distance LIMIT 0 , 20` 
+1

ありがとうたくさんの男 – JANNURM

+0

私の喜びです。 –

関連する問題