日期:2014-05-18  浏览次数:20452 次

联合语句排序问题
我要把三个表ABC联合起来按BZH和ND排序查询  
A表 
select bzh,ztw,czlb from grjbb
B表  
select bzh,nd,gzlj1 as 缴费表上半年,gzlj2 as 缴费下半年 from grjfb  
C表
select bzh,(jfgz1+jfgz2+jfgz3 +jfgz4 +jfgz5 +jfgz6)as 详细上半年,(jfgz7+jfgz8+jfgz9 +jfgz10 +jfgz11 +jfgz12)as 详细下半年 from jfmxb


怎么放在一起并且按BZH和ND排序?

------解决方案--------------------
try
SQL code
select a.bzh as 保障号,a.ztw as 状态,a.czlb as 财政类别, b.nd as 年代,b.GZLJ1 as 缴费表上半年,c.JFGZ1+c.JFGZ2+c.JFGZ3+c.JFGZ4+c.JFGZ5+c.JFGZ6 as 详细上半年
from grjbb as a,grjfb as b,jfmxb as c
where a.bzh=b.bzh and a.bzh=c.bzh 
and a.czlb=2 
and b.nd=c.nd
and b.GZLJ1<>c.JFGZ1+c.JFGZ2+c.JFGZ3+c.JFGZ4+c.JFGZ5+c.JFGZ6