好比現有一張表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;