一些不知道爲什麼執行出錯的SQl語句,往往是因爲你不瞭解他的執行順序。
Select distinct top n [percent] 列名
from 表名
where 條件
group by ... having ...
order by ... asc/desc
執行順序
1>...from 表
2>...where 條件
3>...group by 列
4>...having 篩選條件
5>...Select >選擇列 >distinct
6>...order by 列
7>...Top(最後計算)