当前位置: 代码迷 >> Sql Server >> 如何查询多个表把其中一些列计算给一个变量
  详细解决方案

如何查询多个表把其中一些列计算给一个变量

热度:97   发布时间:2016-04-27 14:56:37.0
怎么查询多个表把其中一些列计算给一个变量?
SQL code
declare @a int select set @a=a.us+b.uc,[email protected],@a+b.count [email protected]from a inner join b on a.id=b.id这样写是错误的.


------解决方案--------------------
SQL code
select /*set*/ @a=a.us+b.uc,[email protected],@a+b.count [email protected]from a inner join b on a.id=b.id-- no set
------解决方案--------------------
declare @a int
declare @b int
select @a=(a.us+b.uc) from a,b where a.id=b.id
select @b=count(b.id) from a,b where a.id=b.id
select @[email protected]
------解决方案--------------------
要么set 要么select 写在一起就不对了。


------解决方案--------------------
SQL code
select @a=a.us+b.uc,[email protected],@a+b.count [email protected]from a inner join b on a.id=b.idset @a=(select (a.us+b.uc) from a inner join b on a.id=b.id)
  相关解决方案