create table pairs (number a, number b)
其中数据是
1,1
1,1
1,1
2,4
2,4
3,2
3,2
5,1
何种查询给了我所有唯一对加上代表的是对的次数列出现。即:
1,1,3
5,1,2
2,4,2
3,2,1
注:这是如此质疑Distinct pair of values SQL但与添加的 “数” 栏要求
create table pairs (number a, number b)
其中数据是
1,1
1,1
1,1
2,4
2,4
3,2
3,2
5,1
何种查询给了我所有唯一对加上代表的是对的次数列出现。即:
1,1,3
5,1,2
2,4,2
3,2,1
注:这是如此质疑Distinct pair of values SQL但与添加的 “数” 栏要求
select
a,b,count(*) c
from
pairs
group by
a,b
而不是'count(*)c'你是指'count(*)as c'? –
是的,这是T-SQL(SQL Server),也许是你需要的其他RDBMS。 – Alex
提示:'GROUP BY'。 –
'(2,4)'与'(4,2)'不同吗? –
@ClodoaldoNeto是的,a = 2,b = 4将不同于a = 4,b = 2 –