子查询: ---------------------------------------------------------- select t.a,t.b,t.c,(t.a+t.b+t.c)as sumabc from (select (select a from tab1) as a1, (select b from tab2) as b1, (select c from tab3) as c1 from ParentTab) t
select rtrim(a)+rtrim(b)+rtrim(c) as sumabc from ParentTab
子查询: ---------------------------------------------------------- select t.a1,t.b1,t.c1,(t.a1+t.b1+t.c1)as sumabc from (select (select a from tab1) as a1, (select b from tab2) as b1, (select c from tab3) as c1 from ParentTab) t
TO:libin_ftsafe(子陌红尘|潇湘剑公子@dev-club) ,你这种方法行是行,但这不是我想要的,因为有可能是 select (select other from othertab) as other1, (select a from tab1) as a1, (select b from tab2) as b1, (select c from tab3) as c1, -------问题所在,如何实现下面这个呢-------------- (select a+b+c) as sumabc from ParentTab
(select other from othertab) as other1, 这句话什么意思。就是说查询的表可能不同吗。
你要节省SQL长度,就用字符串变量做。
没有人回答吗?其实就是想实现: select (select tt1 from tabtt1) as t1, (select tt2 from tabtt2) as t2, ....... (select ttn from tabttn) as tn, (select a from tab1) as a1, (select b from tab2) as b1, (select c from tab3) as c1, -------问题所在,如何实现下面这个呢-------------- (select a1+b1+c1) as sumabc from ParentTab
呀,那我的SQL语句重复度很高了,呵呵
多谢libin_ftsafe(子陌红尘|潇湘剑公子@dev-club) 的提醒!
学习 SQL Server 啊 努力 奋斗-----------------------------------------------------
----------------------------------------------------------
select
t.a,t.b,t.c,(t.a+t.b+t.c)as sumabc
from
(select
(select a from tab1) as a1,
(select b from tab2) as b1,
(select c from tab3) as c1
from ParentTab) t
----------------------------------------------------------
select
t.a1,t.b1,t.c1,(t.a1+t.b1+t.c1)as sumabc
from
(select
(select a from tab1) as a1,
(select b from tab2) as b1,
(select c from tab3) as c1
from ParentTab) t
select
(select other from othertab) as other1,
(select a from tab1) as a1,
(select b from tab2) as b1,
(select c from tab3) as c1,
-------问题所在,如何实现下面这个呢--------------
(select a+b+c) as sumabc
from ParentTab
这句话什么意思。就是说查询的表可能不同吗。
select
(select tt1 from tabtt1) as t1,
(select tt2 from tabtt2) as t2,
.......
(select ttn from tabttn) as tn,
(select a from tab1) as a1,
(select b from tab2) as b1,
(select c from tab3) as c1,
-------问题所在,如何实现下面这个呢--------------
(select a1+b1+c1) as sumabc
from ParentTab