Output is
Image content just shows the brackets, don't show
O great god appeared
CodePudding user response:
with a as (
Select '1' FXH, fa 'c', 'e' fb from dual
The union
Select FXH '2', 'c' fa, 'e' fb from dual
The union
Select '3' FXH, fa 'c', 'e' fb from dual
The union
Select FXH '4', 'c' fa, 'f' fb from dual
The union
Select the '5' FXH, fa 'c', 'f' fb from dual
The union
Select '6' FXH, fa 'd', 'g' fb from dual
The union
Select the '7' FXH, fa 'd', 'g' fb from dual
The union
Select the '8' FXH, fa 'd', 'g' fb from dual
The union
Select the '9' FXH, 'd' fa, 'h' fb from dual
)
SELECT b. a. as "the first column," b. b as "appear the most", ct as "the number of occurrences of the FROM (
The SELECT Max (ct) over (partition by fa) maxct, a. * FROM (
SELECT count (fb) over (partition by fa, fb) ct, fa, fb, row_number () over (partition by fa, fb order by fa) rn, FXH
FROM a
) where a a.r n=1
B) where maxct=ct
Recent brain a little smoke, might be a bit complicated, but you can complete your demand, also hope to have the thigh to write a simple SQL, to learn
CodePudding user response:
Look at the building requirements, if is tied for the most is a show or display only a, if all show that the second floor is no problemCodePudding user response:
with the test as
(select the 'c', 'e' b from dual
Union all select 'c', 'e' b from dual
Union all select 'c', 'e' b from dual
Union all select 'c' a, 'f' b from dual
Union all select 'c' a, 'f' b from dual
Union all select 'd' a, 'g' b from dual
Union all select 'd' a, 'g' b from dual
Union all select 'd' a, 'g' b from dual
Union all select 'd' a, 'h' b from dual)
Select a, b, c
The from
(select a, b, c, rank () over (partition by a order by c desc) rn
The from
Select a, b, count, (b) c from the test group by a, b))
Where an rn=1;
CodePudding user response:
Table named X, SQL is as follows:SELECT a, b, CNT
The FROM (SELECT a, b, CNT, row_number () over (PARTITION BY a ORDER BY DESC) CNT rn
The FROM (SELECT a, b, COUNT (b) over (PARTITION BY a, b) CNT FROM x))
WHERE an rn=1;
CodePudding user response:
Select A, B, count (1) the from tableGroup by A and B
CodePudding user response:
Just don't understand all, changed theSelect A, B, d
The from (select A,
B,
D,
Dense_rank () over (partition by A order by d desc) RNN
The from (select A, B, count (1) d from table t group by A, B))
Where RNN=1;
CodePudding user response: