日期:2014-05-16  浏览次数:20799 次

sql高手进
SELECT   gongid   ,
(SELECT   COUNT(cdt)FROM   kqj       )   AS                   cdc,
(SELECT   COUNT(ztt)   FROM   kqj     )   AS                   ztc,
(SELECT   sum(jbs)   FROM   jb   )   AS   jbs
    FROM   workerinfo;


我想在SQL语句中同时把cdc,ztc相加怎么办?

------解决方案--------------------
select * ,cdc-ztc from(
SELECT gongid ,
(SELECT COUNT(cdt)FROM kqj ) AS cdc,
(SELECT COUNT(ztt) FROM kqj ) AS ztc,
(SELECT sum(jbs) FROM jb ) AS jbs
FROM workerinfo;
) as t