SQL多表汇总字段合并查询

"SELECT nsrxx.nsrsbh, nsrxx.nsrmc," +
                                   "(CASE WHEN younum >= 0 THEN younum ELSE 0 END) AS younum,(CASE WHEN fpnum >= 0 THEN fpnum ELSE 0 END) AS fpnum," +
                                   "round(younum /fpnum,2) ," +
                                   "swjg FROM (nsrxx LEFT JOIN (SELECT nsrsbh, SUM(sl) AS younum FROM youprkdj where rq  between '" + dt1 + "' and  '" + dt2 + "' GROUP BY nsrsbh) youprkdj ON nsrxx.nsrsbh = youprkdj.nsrsbh )" +
                                   " LEFT JOIN (SELECT nsrsbh, SUM(sl) AS fpnum FROM zengzsfpxx where rq  between '" + dt1 + "' and  '" + dt2 + "'" +
                                   " GROUP BY nsrsbh) zengzsfpxx ON nsrxx.nsrsbh = zengzsfpxx.nsrsbh" +
                                   " LEFT JOIN (SELECT swjgdm, swjg FROM dm_swjg) swjgmc ON LEFT(nsrxx.swjgdm," + FormMain.swjgYxws + ") = '"
                                   + FormMain.stSwjgdm.Substring(0, FormMain.swjgYxws) + "' and LEFT(swjgmc.swjgdm," + FormMain.swjgYxws + ") = '"
                                   + FormMain.stSwjgdm.Substring(0, FormMain.swjgYxws) + "' where swjg is not null";

你可能感兴趣的:(计算机,sql,join,null)