a.语句select distinct a,b,c from t_table与select distinct a from t_table在查询结果上的区别。
区别:select distinct a,b,c from t_table 查找a+b+c列都不重复的。select distinct a from t_table 查找a列不重复的。
b. distinct 修饰是针对行,不要误以为是针对首字段。 即,不是误以为select distinct (a),b,c from t_table只是查询出a列不重复的数据(以前我一直是这么认为的)。
c. 微软建议只用1列 大多用在聚合函数里 不然有时出问题。
在棸合函数中的使用的例子:
count(distinct t.VC_BSFLAG) over(partition by t.d_date,t.vc_stockcode,t.vc_fundcode) count1
d. distinct可以认为是select完后才进行的,所有select distincta, b, c from t_table,相当于select a,b,c from t_table之后再对所有列distinct。(这也从侧面说明了distinct是针对行的,而不是针对某一列)
容易误解的distinct
最新推荐文章于 2022-09-06 22:31:36 发布