当前位置: 代码迷 >> Sql Server >> EXISTS子查询的有关问题
  详细解决方案

EXISTS子查询的有关问题

热度:62   发布时间:2016-04-27 11:00:47.0
EXISTS子查询的问题
我要将EXISTS子查询的结果应用到上层的select中 
如
select id,totalproduct/(usetime) from detail a
where exists(select name,id,datediff(getdate(),creatdate) as usetime from product where id=a.id)
当然这是错误的 usetime不识别
有木有什么方法可以将子查询的这个结果usetime传到外围那个SELECT 中

------解决方案--------------------
不能,exists 返回的是boolean,没有数据集的返回,外围无法使用
LZ这个只能用子查询或者是连接表的方式处理了。 

------解决方案--------------------
exists只判断存在与否,你如果要实现,那就要用连接
------解决方案--------------------
try this,
SQL code
select a.id,       a.totalproduct/datediff(d,getdate(),p.creatdate) from detail ainner join product p on a.id=p.id
  相关解决方案