2017-09-14 202 views
-6

我想在一個語句中執行這些查詢: - 如何TO?查詢,獲得結果再次查詢

SELECT count(id) as levela FROM `member` where parent_id in (SELECT id FROM `member` where parent_id in (SELECT id FROM `member` where parent_id = 2)) 

SELECT count(id) as levelb FROM `member` where parent_id in (SELECT id FROM `member` where parent_id = 2) 

SELECT count(id) as levelb FROM `member` where parent_id = 2 
+0

所以有什麼問題? –

+0

@JurijJazdanov如何做到這一點????????????????????????/ –

+0

你想從所有3個查詢中得到總數? –

回答

0

改用'where','where in' - where in允許你在數組中搜尋。 例如:

Select id from member where parent_id IN (here array ($y)) 
+0

剛剛編輯我的問題.... Plz再次看看 –

0

我認爲你可以使用這個

SELECT id FROM member where parent_id IN (x, y, z) 

如果有困難,你可以使用這樣的子查詢:

SELECT id FROM member where parent_id IN (SELECT id FROM list_parent_id WHERE "condition you want to find") 

希望這有助於=)

+0

剛剛編輯我的問題.... Plz再次看看 –

+0

你可以使用UNION聲明,希望這可以幫助你 –