------distinct 去重复查询 select * from accounts acc join (select distinct accid from roles) r on r.accid=acc.ID -----不需要distinct select * from (select MAX(ID)roleid,accid from roles group by accid) rr join (select * from accounts) acc on acc.ID=rr.accid
查询公司与公司最新刷新的一条信息 select t1.userid,t1.id,t1.title,t1.RegType,t1.Salary,t1.SubjectID,t1.RefreshTime,t2.name,t2.logo,t2.[address],t2.CreateTime from info t1 inner join companyinfo t2 on t1.userid=t2.id where t1.id in ( info.id from info where userid = t
原本的的一张表,填写数据的字段为字符串varchar2类型,然后进行排序的时候,就会出现问题.会默直接默认判断为第一个数字9最大,而不判断整个数字的大小. 所以,就要用到TO_NUMBER函数 select * from T_GRGJJJCXX t order by TO_NUMBER(t.c_ye) desc 直接就可以把这个纯数字的字段改成number类型进行排序. 然后查询的时候,发现数据重复过多,这时候,根据某个字段判断重复数据,我初步根据的是姓名去判断,我写的为 select t.na
1.利用group by 去重复 2.可以利用下面的sql去重复,如下 1) select id,name,sex from (select a.*,row_number() over(partition by a.id,a.set order by name) su from test a ) where su=1 2)select id,name,sex from (select a.*,row_number() over(partition by a.id,a.sex order by n
数据库查询的基本格式为: select ----输出(显示)你要查询出来的值 from -----查询的依据 where -----筛选条件(对依据(数据库中存在的表)) group by -----对筛选后的数据 进行分组 having ----- 筛选条件(对分组后的结果再次筛选) order by -----将结果进行排序 注意:基本语法格式顺序不能变,顺序不能变,但可以缺省 表结构操作 表结构操作是需要去修改表结构,使用的关键字是alter,其他方式无法对表进行操作的时候,比如,新增列,
name like 'ja%'; select * from student where name not like '%[j,n]%'; select * from student where name like '%[j,n,a]%'; select * from student where name like '%[^ja,as,on]%'; select * from student where name like '%[ja_on]%'; --in 子查询 , ); --not in
SQL Server T-SQL高级查询 高级查询在数据库中用得是最频繁的,也是应用最广泛的. Ø 基本常用查询 --select select * from student; //查询student表中所有字段. --all 查询所有 select all sex from student; --distinct 过滤重复 select distinct sex from student; --count 统计 select count(*) from student; selec
高级查询在数据库中用得是最频繁的,也是应用最广泛的. Ø 基本常用查询 --select select * from student; --all 查询所有 select all sex from student; --distinct 过滤重复 select distinct sex from student; --count 统计 select count(*) from student; select count(sex) from student; select count(di