当前位置:Gxlcms > 数据库问题 > 常用SQL语句的整理--SQL server 2008(查询三--子查询)和guid

常用SQL语句的整理--SQL server 2008(查询三--子查询)和guid

时间:2021-07-01 10:21:17 帮助过:3人阅读

ROW_NUMBER() over(order by id)as num,*from gb_data where num>5and num<10--这行代码是错误的,因为系统识别不出来num是多少,为什么呢?

--是因为执行顺序的问题,sql语句是先执行from,然后执行where,最后执行select

--正确的写法如下

select *from (select ROW_NUMBER() over(order by id)as num,*from gb_data) as t where t.num>5and t.num<10

--子查询(以查询的表作为条件,在基础上进行第二次的查询)查询所有书出版的年份入会的读者信息

select*from Reader where FYearOfJoin in(select FyearPublished from Book)

GUID:Server中生成GUID的函数是newid()

insert into t_table (id) values (newid())

 

常用SQL语句的整理--SQL server 2008(查询三--子查询)和guid

标签:

人气教程排行