1.distinct单列 select distinct(a) from tableA; 2.distinct多列 select distinct a,b,c from tableA; 注意此时是将a,b,c三列所有不同的组合全部列出来,而不仅仅只是distinct a 相当于以下语句: select a,b,c from tableA group by a,b,c 3.另外一种的distinct多列 其实这篇文章的最初需求如下: 想分别查某一张表的几个字段的distinct值 select d
当select distinct a,b,c时,只会对a.b.c都起作用,无法达到只顾虑多余的a列: 根据hive官方网站说明:当有表 a b 10 1 10 2 10 3 此时select a,b from test group by a是无法工作的,因为hive不知道你是要取第一行的b还是取最小的b,所以选择权交给用户. 可以这样达到效果:select a ,min(b) b from test group by a MySQL等其他数据库默认是支持的,并且默认是取第一行
drop table test1; create table test1 as select * from dba_objects where rownum<1000; drop table test2; create table test2 as select * from dba_objects where rownum<1000; insert into test1 select * from test1; update test2 set owner='SCOTT'; BEGIN DB
.SELECT TOP 规定返回记录的数目(对于大型数据库很有用的) SELECT TOP number|percent column--name FROM table; 1.2 SELECT LIMIT 限制数量的 ; 1.3 ROWNUM 限制 ; 返回Person表中不大于5个的数据: PERCENT * FROM websites: 返回前 百分之50的数据: .LIKE 用于在WHERE语句中搜索列中的制定模式 SELEC name FROM table WHERE name LIKE
MYSQL SQL语句技巧初探(一) 本文是我最近了解到的sql某些方法()组合实现一些功能的总结以后还会更新: rand与rand(n)实现提取随机行及order by原理的探讨. Bit_and,bit_or,bit_count等位操作方法实现统计功能. rand与rand(n)提取 使用order by rand(n)配合limit n可以提起相应的n个随机样本. 如:select * from student grade=’2’ order by rand() limit 5 随机提