[英]select from t1 where count of something inside t2 is greater than zero
t1
有id
status
price
t2
有id
status
city
如果status
為active
並且t2.status = active
計數大於0
,則想要從t1
選擇全部;
就像是:
select id, status, price from t1 where status = 'active'
AND
count of (select status from t2 where status = 'active') > 0 order by t1.price;
換句話說-如果active
存在t2.status
有什么幫助嗎?
我認為你應該更多地向我們解釋你的問題。 但我認為這是您正在尋找的Query
SELECT TABLE1.id ,TABLE1.status ,TABLE1.price ,
if(TABLE1.status = 'active' AND (SELECT COUNT(*) FROM
(SELECT t2.* FROM t2 WHERE stackoverflow1.t2.status = 'active' > 0) t2) ,"yes","no")
FROM t1 TABLE1 ,t2 TABLE2 GROUP BY TABLE1.price
SELECT id, status, price
FROM
Table1
WHERE status = 'active'
AND EXISTS(
SELECT status
FROM Table2
WHERE status = 'active'
)
ORDER BY price;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.