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

简单sql问题 小弟不会 下班结帖
SQL code
select distinct a.*,b.LT_TEAMGROUP,c.li_name from TM_ORDER as a inner join LI_TM_CYCLETIME as b on a.TO_TEAM_ID=b.LT_ID LEFT join LI_LINEPRODUCT as c on a.TO_LINE_ID=c.LI_ID order by a.TO_ID desc

我想把上面的一个sql改成 以TM_ORDER 做为主表 查询的时候只要根据TM_ORDER 表条件查询就行 请问高手怎么改? thanks

------解决方案--------------------
直接在where后面加条件不就行了吗??没明白意思。
------解决方案--------------------
直接在where后面加条件不就行了吗??没明白意思。
------解决方案--------------------
SQL code

--楼主是不是想用left join进行联接
select distinct a.*,b.LT_TEAMGROUP,c.li_name from TM_ORDER as a left join LI_TM_CYCLETIME as b on a.TO_TEAM_ID=b.LT_ID LEFT join LI_LINEPRODUCT as c on a.TO_LINE_ID=c.LI_ID order by a.TO_ID desc

------解决方案--------------------
SQL code

--楼主是不是想用left join进行联接
select distinct a.*,b.LT_TEAMGROUP,c.li_name from TM_ORDER as a left join LI_TM_CYCLETIME as b on a.TO_TEAM_ID=b.LT_ID LEFT join LI_LINEPRODUCT as c on a.TO_LINE_ID=c.LI_ID order by a.TO_ID desc

------解决方案--------------------
这样?
SQL code
select distinct a.*,b.LT_TEAMGROUP,c.li_name 
from TM_ORDER as a left join LI_TM_CYCLETIME as b on a.TO_TEAM_ID=b.LT_ID 
LEFT join LI_LINEPRODUCT as c on a.TO_LINE_ID=c.LI_ID 
order by a.TO_ID desc

------解决方案--------------------
探讨

这样?
SQL code
select distinct a.*,b.LT_TEAMGROUP,c.li_name
from TM_ORDER as a left join LI_TM_CYCLETIME as b on a.TO_TEAM_ID=b.LT_ID
LEFT join LI_LINEPRODUCT as c on a.TO_LINE_ID=c.LI_ID
order by……

------解决方案--------------------
这样?
SQL code
select distinct a.*,b.LT_TEAMGROUP,c.li_name from TM_ORDER as a inner join LI_TM_CYCLETIME as b on a.TO_TEAM_ID=b.LT_ID LEFT join LI_LINEPRODUCT as c on a.TO_LINE_ID=c.LI_ID
where a.column='条件'
 order by a.TO_ID desc