我的查询是:
SELECT
t.*
FROM
(SELECT
ig_idx,
--, count(ig_root) over(partition by ig_root) AS GameCount1
ig_root,
ig_game_type,
ROW_NUMBER() OVER (PARTITION BY ig_root
ORDER BY CASE WHEN ig_game_type IN ('12', '1x2') THEN 0 ELSE 1 END, ig_game_type ASC) AS seqnum
FROM
Info_Game) AS t
ORDER BY
ig_root, seqnum
相同数量的ig_root,seqnum = 1和type =' 12'或者输入=' 1x2' 我想得到相同数量的ig_root
ig_idx ig_root ig_game_type seqnum
1 11 12 1
2 11 ah 2
3 11 ou 3
4 12 12 1
5 13 1h_ah 1 <--- this
9 13 1h_ou 2
6 13 2h_ou 3
7 13 ah 4
8 13 ou 5
10 14 1x2 1
11 14 1h_ah 2
14 14 1h_ou 3
12 14 h 4
13 14 ou 5
idx 5:这意味着seqnum为1, 但类型不是12或1x2。 所以我不想带ig_root 13号。
像这样:ig_idx ig_root ig_game_type seqnum
1 11 12 1
2 11 ah 2
3 11 ou 3
4 12 12 1
10 14 1x2 1
11 14 1h_ah 2
14 14 1h_ou 3
12 14 h 4
13 14 ou 5
答案 0 :(得分:1)
只需过滤即可获得具有1x2或12
的ig_rootWHERE ig_root IN (SELECT ig_root FROM Info_Game WHERE ig_game_type IN ('1x2', '12')