好比现有一张表user:sql
id name age设计
1 a 10it
2 b 15 table
3 c 20select
4 a 10sql语句
5 b 15统计
6 a 15tab
7 b 10co
要求按name和age都相同的去重后统计条目,如上表去重后总行数应该为5。去重
最初设计的sql语句为select count(name) from (select name,age,count(name) from user group by name,age);
结果运行时报错:every derived table must have its own alias。意思是每个派生出的表格都要有一个别名,因而咱们给去重后的表格起个别名subtable,修改后的sql语句以下:
select count(name) from (select name,age,count(name) from user group by name,age)as subtable;