1 つ目の方法は、サブテーブルの合計を求めてメインテーブルに表示する方法です。
SELECT s.gcid,s.xlname,s.xlbm,s.gcname,s.gcyear,s.gcmonth,s.gctypename,s.pfprice,(case s.paystate when 0 then '未支付' when 1 then '部分' when 2 then '结清' else '' end) as paystate,s.gckgdate,s.gcwgdate,s.pfwh,s.htongprice,s.sgcompany,s.sguser,s.jlcompany,s.jluser,s.xlbm,s.xlname,s.zyprice,s.dfprice,(SELECT COALESCE( sum(CAST(c.gcnoeprice AS decimal(18,3))),0) FROM tl_road_aagcgl_pay c WHERE c.gcid=s.gcid) as gcnoeprice ,( s.htongprice- (SELECT COALESCE( sum(CAST(c.gcnoeprice AS decimal(18,3))) ,0) FROM tl_road_aagcgl_pay c WHERE c.gcid=s.gcid) )as gcnowwfprice FROM tl_road_aagcgl s where gcnowwfprice !='0' and s.gcnoeprice !='0'
2 番目に、一時フィールドを検索して処理します。
select * from (SELECT s.gcid,s.xlzh,s.gcbh,s.zzsave,s.gcyear,s.gcmonth,s.gctypename,s.gcname,(case s.paystate when 0 then '未支付' when 1 then '部分' when 2 then '结清' else '' end) as paystate,s.sgcop,s.sguser,s.planprice,s.jsprice,s.bzprice,s.zfdate,s.kgdate,s.wgdate,s.xlbm,s.xlname,s.gcfjsm,(SELECT COALESCE( sum(CAST(c.gcnoeprice AS decimal(18,3))),0) FROM tl_road_zxxx_xmgc_pay c WHERE c.gcid=s.gcid) as gcnoeprice ,( s.jsprice- (SELECT COALESCE( sum(CAST(c.gcnoeprice AS decimal(18,3))) ,0) FROM tl_road_zxxx_xmgc_pay c WHERE c.gcid=s.gcid) ) as gcnowwfprice FROM tl_road_zxxx_xmgc s where (country = '" + country + "') and del='1' ) s where gcnowwfprice ='0' AND gcnoeprice !='0'