首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

sql 语句的查询有关问题

2013-07-20 
sql 语句的查询问题select a.htmc,a.fzbm,a.htje,a.htbm,(select companyName from xt_wldwbm where compa

sql 语句的查询问题
select a.htmc,a.fzbm,a.htje,a.htbm,
(select companyName from xt_wldwbm where companyid=a.jf) as jsdw,
(select top 1 companyid from xt_wldwbm where companyid=a.jf)as jsdwid,
(select xmmc from tjjxmb where xmbh=a.gcbm)as ssxm,
(select companyName from xt_wldwbm where companyid=a.yf) as yf,
(select x.fsz from xmpsdjmx x where x.htbm=a.htbm and x.mainid in(select id from xmpsdj where shjdid='结算' and djstate='9')) as sdje,(select top 1 b.fkrq from ht_zfjd b  where b.htbm=a.htbm )as fkrq,(select top 1 b.fkje from ht_zfjd b  where b.htbm=a.htbm )as fkje
from ht_hz a,xt_wldwbm c where jsdwid='20120005'
带颜色的部分该怎么写呢??
[解决办法]


(select companyName from xt_wldwbm where companyid=a.jf) as jsdw,
 (select top 1 companyid from xt_wldwbm where companyid=a.jf)as jsdwid,
 (select xmmc from tjjxmb where xmbh=a.gcbm)as ssxm,
 (select companyName from xt_wldwbm where companyid=a.yf) as yf,
 (select x.fsz from xmpsdjmx x where x.htbm=a.htbm and x.mainid in(select id from xmpsdj where shjdid='结算' and djstate='9')) as sdje,(select top 1 b.fkrq from ht_zfjd b  where b.htbm=a.htbm )as fkrq,(select top 1 b.fkje from ht_zfjd b  where b.htbm=a.htbm )as fkje

--这里是发挥一张jsdwid表
(select top 1 companyid from xt_wldwbm where companyid=a.jf)as jsdwid

 版主说的没错你这种写法都是返回表而不是字段,建议楼主换join方式发 没见过你这种写法的

热点排行