sql语句 联合查询,需要将两个表中两个字段做减法,若其中一个字段为
答案:3 悬赏:50
解决时间 2021-01-19 18:16
- 提问者网友:niaiwoma
- 2021-01-19 09:30
sql语句 联合查询,需要将两个表中两个字段做减法,若其中一个字段为
最佳答案
- 二级知识专家网友:孤独入客枕
- 2021-01-19 10:38
select a.id from table1 a left join table2 b on a.id=b.id where (a.price -nvl(b.price,0)) >10加个NVL判断一下,如果为空,则视为0即可
追问请问nvl是自己写的一个函数吗?系统提示不存在这个方法
追问请问nvl是自己写的一个函数吗?系统提示不存在这个方法
全部回答
- 1楼网友:归鹤鸣
- 2021-01-19 13:24
引用j1x2h32046的回答:
select a.id from table1 a left join table2 b on a.id=b.id where (a.price -nvl(b.price,0)) >10加个NVL判断一下,如果为空,则视为0即可
select a.id from table1 a left join table2 b on a.id=b.id where (a.price -null(b.price,0)) >10
select a.id from table1 a left join table2 b on a.id=b.id where (a.price -nvl(b.price,0)) >10加个NVL判断一下,如果为空,则视为0即可
select a.id from table1 a left join table2 b on a.id=b.id where (a.price -null(b.price,0)) >10
- 2楼网友:末日狂欢
- 2021-01-19 11:59
先用一条子查询把空值格式化成0,然后再用连接查询
select a.id from (select
case when price is null
then 0
else price
end from table1) a left join(
select
case when price is null
then 0
else price
end from table2
) b on a.id=b.id where (a.price -b.price) >10
select a.id from (select
case when price is null
then 0
else price
end from table1) a left join(
select
case when price is null
then 0
else price
end from table2
) b on a.id=b.id where (a.price -b.price) >10
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯