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

EXISTS子查询的有关问题

2012-09-27 
EXISTS子查询的问题我要将EXISTS子查询的结果应用到上层的select中如select id,totalproduct/(usetime) fr

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 

热点排行