string strSql = (@"select a.bh,(select b.ksmc from ksb as b where b.xh = a.ks) as ks,(select c.gzmc from gzlxb as c where c.bh = a.gzlx) as gzlx
,(select d.zgxm from yggl as d where d.zggh = a.apr) as apr,(select e.zgxm from yggl as e where e.zggh = a.zxr) as zxr
,(select f.zgxm from yggl as f where f.zggh = a.qrr) as qrr,a.zy,a.xxms,a.kssj,a.zxsj,a.jssj,(select g.bz1 from zdb as g where g.xh = a.wcqk and g.lx = '完成情况') as wcqk
,(select h.bz1 from zdb as h where h.xh = a.zy_flag and h.lx = '重要情况') as zy_flag
,(select i.bz1 from zdb as i where i.xh = a.diff and i.lx = '工作分级') as diff
from gzrz as a order by wcqk desc,kssj desc");
这样写是不是不太好
有没有其他写法能够达到要求
------解决思路----------------------
不要对每个字段进行select选择,效率太低,使用inner join 去连接多个表查询
------解决思路----------------------
inner join 可以呀,不知道怎么写可以去查询资料呀。一般的都有例子,你的代码关联表太多,你就逐一分析它们的关系,一个表一个表的关联,没关联一次都测试一次。
几乎没人愿意花费时间来写代码的。
------解决思路----------------------
可以多次使用,使用字段名时候前面缀上表别名就可以,就像你写的