簡體   English   中英

從 t1 中選擇,其中 t2 內的事物計數大於零

[英]select from t1 where count of something inside t2 is greater than zero

t1id status price

t2id status city

如果statusactive並且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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM