首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

请教,into这样用有错吗

2012-01-09 
请问,into这样用有错吗?select购物人,count(购物名称)asspintonew_salesfromsaleswhere数量 0groupby购

请问,into这样用有错吗?
select   购物人,count(购物名称)   as   sp   into   new_sales   from   sales   where   数量 <> 0   group   by   购物人
select   *   from   new_sales   where   sp> 2
这条语句是可以实现的
select   *   from   (select   购物人,count(购物名称)   into   new_sales   from   sales   where   数量 <> 0   group   by   购物人)   where   count(购物名称)> 2  
这条语句在运行的时候提示into附近有错误

请问into不能这样用吗?



[解决办法]
select * from (select 购物人,count(购物名称) as sp from sales where 数量 <> 0 group by 购物人) new_sales where sp> 2
[解决办法]
不能在子查询中使用into
[解决办法]
肯定不能
你可以这样
select * from (select 购物人,count (购物名称) as 购物名称 from sales where 数量 <> 0 group by 购物人) a where 购物名称> 2
[解决办法]
select 购物人,count (购物名称)
from sales
where 数量 <> 0
group by 购物人
having count (购物名称)> 2
这样结果是一样的
[解决办法]
子查询不能使用 Order By/Compute/Into 子句。
除非同时指定了 Top,否则 Order By 子句在子查询中无效。

热点排行
Bad Request.