这样的数值 怎么取出来

lanmou1983 2012-02-28 02:08:43
表A ID 面积 金额

表B ID NEWID(录入表A中的一个ID) OLDID(录入表A中的一个ID)

需要 根据表B中的 NEWID 和 OLDID 找到表A中对应的面积 金额 用 OLD面积 - NEW面积 用OLD金额 - NEW金额
...全文
162 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
walkman_22 2012-02-29
  • 打赏
  • 举报
回复
在mysql下测试通过的。oracle应该也没有问题。
walkman_22 2012-02-29
  • 打赏
  • 举报
回复

select a2.cost-a1.cost, a2.area-a1.area
from A a1, A a2, B b
where a1.ID=b.NEWID and a2.ID=b.OLDID
cmzzlz 2012-02-28
  • 打赏
  • 举报
回复
请问这样的话 逻辑怎么走
ssqtjffcu 2012-02-28
  • 打赏
  • 举报
回复

select t1.id, t1.面积 - t2.面积, t1.金额 - t2.金额
from (select 表B.id, 面积, 金额 from 表B,表A where 表B.newid = 表A.id) t1,
(select 表B.id, 面积, 金额 from 表B,表A where 表B.oldid = 表A.id) t2
where t1.id = t2.id
hupeng213 2012-02-28
  • 打赏
  • 举报
回复
把A表做个别名,直接查询就行了
select b.newid,a.area,a.money,b.oldid,c.area,c.money,c.area - a.area,c.money - a.money
from A a,B b,A c
where b.newid=a.id
and b.oldid=c.id
benluobo 2012-02-28
  • 打赏
  • 举报
回复

select (select square from A where id = oldId) - (select square from A where id= newId) (OLD面积 - NEW面积), (select money from A where id = oldId) - (select money from A where id=newId) (用OLD金额 - NEW金额) from dual
benluobo 2012-02-28
  • 打赏
  • 举报
回复

select (select square from A where id = oldId) - (select square from A where id= newId) OLD面积 - NEW面积, (select money from A where id = oldId) - (select money from A where id=newId) 用OLD金额 - NEW金额 from dual

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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