-2
こんにちは、IDフィールドでN個の値がXの値に等しい場合、「見つける」方法がありますか?ここで少なくともN個のレコードがxと等しい合計
こんにちは、IDフィールドでN個の値がXの値に等しい場合、「見つける」方法がありますか?ここで少なくともN個のレコードがxと等しい合計
は、3つの可能な方法があります。
サブクエリselect t.*, g.n
from yourtable t
inner join (
select id, count(*) as n from yourtable y
where y.col = 'N'
group by id
) g on t.id = g.id
where g.n >= 5
別によって
select *
from (
select t.*
, count(case when t.col='N' then 1 end) over(partition by t.id) as count_n
from yourtable t
) d
where count_n >= 5
以上の伝統的なグループは、この
select t.*, oa.n
from yourtable t
inner join lateral (
select count(*) as n from yourtable y
where y.id = t.id
and y.col = 'N'
) oa on true
where oa.n >= 5
SQLFiddle Demoのように "内側の横の参加" を使用することです
[how-to-ask](https://stackoverflow.com/help/how-to-ask)を最初にお読みください。 –
あなたの質問が正確に答えるほど詳細でない場合は、広範な「一般的な」回答しか得られません –
申し訳ありませんが、2つの列と多分多くの方法しかないので質問が十分に分かりました。 – BernardL