[英]Postgres get rows having at least 1 specific value in column group by another column
我有一個sql命令:
select location,status,total from my_table
這個回報:
location - status - total
city a - active - 3
city a - pending - 2
city a - cancel - 4
city b - pending - 4
city b - cancel - 4
city c - active - 2
city c - cancel - 6
如何僅返回城市中至少有一次狀態為活動且總數> = 1的行?
所以,我想回歸:
location - status - total
city a - active - 3
city a - pending - 2
city a - cancel - 4
city c - active - 2
city c - cancel - 6
當你注意到我不想返回城市b因為它至少有一次活動狀態沒有活動,總數> = 1。
select location,status,total from my_table
where location in (
select location from my_table
where status = 'active'
and total >= 1
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.