请大家来看看如下的SQL这么写。非常着急!!!(100分)

  • 主题发起人 主题发起人 liuxiaouo
  • 开始时间 开始时间
L

liuxiaouo

Unregistered / Unconfirmed
GUEST, unregistred user!
有两表如下:
table1:
wareno name amount
001 aaa 10
002 bbb 20
003 ccc 35
004 ddd 25
table2:
wareno paycurr
001 2000
002 1000

我想要的结果是:
wareno name amount paycurr
001 aaa 10 2000
002 bbb 20 1000
003 ccc 35 0
004 ddd 25 0

 
select * from table1 a left jion table2 b on a.wareno=b.wareno
 
select a.wareno,a.name,a.amount,isnull(a.amount*b.paycurr,0) paycurr
from table1 a,table2 b
where a.wareno*=b.wareno
 
select a.*,b.paycurr from table1 a left jion table2 b on a.wareno=b.wareno;
 
Select C.*,IsNull(Cast(paycurr as integer),0) As Paycurr
from Table2 as S Right Join Table1 As C on S.wareno=C.wareno
 
select a.wareno , a.name, a.amount ,nvl(b.paycurr,0)
from table1 a,table2 b
where a.wareno =b.wareno;
nvl 是oracel函数,意思是如果 b.paycurr为空,用0替代
其他数据库也有类似函数
 
select wareno,name,amount,paycurr
from table1,table2
where wareno in(select wareno from table2);
select wareno,name,amount,"0"
from table1 where wareno not in(select wareno from table2);
 
左联,同意以下:
select a.*,b.paycurr from table1 a left jion table2 b on a.wareno=b.wareno;
 
感谢大家!
hg1780428先回答,所以分数高一点
 
后退
顶部