sql语句求教: 一段sql语句的修改,求教送分,谢谢

lhaaaaaa 2002-12-20 03:57:25
SELECT T_SALE.SA_ID,
T_SALE.CUST_ID,
T_SALE.zyqx_date,
T_SALE.DEP_ID,
T_SALE.T_AMT,
T_SALE.EMP_ID,
T_SALE.PAY_AMT,
T_SALE.currency,
t_sale.txtqty,
t_rec.rec_date,
t_rec.rec_status
FROM T_SALE,t_rec_item,t_rec
where (t_sale.sa_id = t_rec_item.sa_id)and
(t_rec_item.rec_id = t_rec.rec_id)


sql语句求教:
如上有三个表T_SALE,t_rec_item,t_rec通过sa_id,和rec_id的关联可以带出数据
但是如果表t_rec_item,t_rec中没有的数据就带不出来

我想取出t_sale的所有数据,如果表t_rec_item,t_rec中有数据就显示出来否则,依然把t_sale中的所有数据带出来,这个sql语句应该怎么修改???
...全文
27 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
alexwoowf 2002-12-23
  • 打赏
  • 举报
回复
SELECT T_SALE.SA_ID,
T_SALE.CUST_ID,
T_SALE.zyqx_date,
T_SALE.DEP_ID,
T_SALE.T_AMT,
T_SALE.EMP_ID,
T_SALE.PAY_AMT,
T_SALE.currency,
t_sale.txtqty,
isnull(t_rec.rec_date,‘你想显示的’),
isnull(t_rec.rec_status,你想显示的’)
FROM T_SALE ,t_rec_item,t_rec
WHERE t_sale.sa_id*=t_rec_item.sa_id and
t_sale.sa_id*=t_rec.rec_id

yinzhen 2002-12-21
  • 打赏
  • 举报
回复
SELECT T_SALE.SA_ID,
T_SALE.CUST_ID,
T_SALE.zyqx_date,
T_SALE.DEP_ID,
T_SALE.T_AMT,
T_SALE.EMP_ID,
T_SALE.PAY_AMT,
T_SALE.currency,
t_sale.txtqty,
t_rec.rec_date,
t_rec.rec_status
FROM T_SALE
LEFT JOIN t_rec_item on t_sale.sa_id = t_rec_item.sa_id
LEFT JOIN t_rec ON t_rec_item.rec_id= t_rec.rec_id
alexwoowf 2002-12-20
  • 打赏
  • 举报
回复
用 where ....*=.......也可以!
SELECT T_SALE.SA_ID,
T_SALE.CUST_ID,
T_SALE.zyqx_date,
T_SALE.DEP_ID,
T_SALE.T_AMT,
T_SALE.EMP_ID,
T_SALE.PAY_AMT,
T_SALE.currency,
t_sale.txtqty,
t_rec.rec_date,
t_rec.rec_status
FROM T_SALE ,t_rec_item,t_rec
WHERE t_sale.sa_id*=t_rec_item.sa_id and
t_sale.sa_id*=t_rec.rec_id
ZHANGWEI15 2002-12-20
  • 打赏
  • 举报
回复
SELECT T_SALE.SA_ID,
T_SALE.CUST_ID,
T_SALE.zyqx_date,
T_SALE.DEP_ID,
T_SALE.T_AMT,
T_SALE.EMP_ID,
T_SALE.PAY_AMT,
T_SALE.currency,
t_sale.txtqty,
t_rec.rec_date,
t_rec.rec_status
FROM T_SALE LEFT JOIN t_rec_item ON t_sale.sa_id = t_rec_item.sa_id
LEFT JOIN t_rec ON t_rec_item.rec_id = t_rec.rec_id
lhaaaaaa 2002-12-20
  • 打赏
  • 举报
回复
是不是用LEFT OUTER JOIN,但是不太会用,谢谢

34,873

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧