时间:2021-07-01 10:21:17 帮助过:3人阅读
--是因为执行顺序的问题,sql语句是先执行from,然后执行where,最后执行select
--正确的写法如下
- <span style="color: #0000ff;">select</span> *<span style="color: #0000ff;">from</span> (<span style="color: #0000ff;">select</span> ROW_NUMBER() over(order by id)<span style="color: #0000ff;">as</span> num,*<span style="color: #0000ff;">from</span> gb_data) <span style="color: #0000ff;">as</span> t <span style="color: #0000ff;">where</span> t.num>5and t.num<<span style="color: #800080;">10</span>
--子查询(以查询的表作为条件,在基础上进行第二次的查询)查询所有书出版的年份入会的读者信息
- <span style="color: #0000ff;">select</span>*<span style="color: #0000ff;">from</span> Reader <span style="color: #0000ff;">where</span> FYearOfJoin <span style="color: #0000ff;">in</span>(<span style="color: #0000ff;">select</span> FyearPublished <span style="color: #0000ff;">from</span> Book)
GUID:Server中生成GUID的函数是newid()
- insert into t_table (id) values (newid())
常用SQL语句的整理--SQL server 2008(查询三--子查询)和guid
标签: