问一个select 简单的问题(50)

W

wlyft

Unregistered / Unconfirmed
GUEST, unregistred user!
有两表A表字段名1 字段名21 王2 李3 林...B表字段名1 332113然后想一条select句子 得出 林 3 林 3 李 2 王 1 王 1 林 3这语句怎么写?
 
确实够简单select a.字段名2,b.字段名1 from b left join a on b.字段名1=a.字段名1
 
楼上回答正确
 
select a.字段名2,b.字段名1 from B表 innerjoin A表 on b.字段名1=a.字段名1
 
支持2楼,常规有效的方法。
 
使用后 sql.add('select CustomerAccount.customername,' +'movehistory.accountid,' +'movehistory.SN,' +'movehistory.oddNO,' +'movehistory.goodsname,' +'movehistory.wmodel,' +'movehistory.movepiece,' +'movehistory.oldlocation,' +'movehistory.oldarea,' +'movehistory.worktime,' +'movehistory.affirmMen,' +'movehistory.remark' +' from movehistory left outer join CustomerAccount on ' +' movehistory.accountid=CustomerAccount.accountid ' +sqlstr+' order by accountid,sn');得出的文本为select CustomerAccount.customername,movehistory.accountid,movehistory.SN,movehistory.oddNO,movehistory.goodsname,movehistory.wmodel,movehistory.movepiece,movehistory.oldlocation,movehistory.oldarea,movehistory.worktime,movehistory.affirmMen,movehistory.remark from movehistory left outer join CustomerAccount on movehistory.accountid=CustomerAccount.accountid where (worktime between '2008-12-31 11:56:25' and '2009-12-31 11:56:25') order by accountid,sn出错信息为:列名accountid 不明确可是我在SQLserver2000里执行是可以的,大哥们速回
 
+sqlstr+' order by accountid,sn');在最后这里没有指明是哪个表的字段
 
多人接受答案了。
 
顶部