日期:2014-05-19  浏览次数:20389 次

请问,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 子句在子查询中无效。