如何在sql中减去两个查询? [英] How can I subtract two queries in sql?

查看:63
本文介绍了如何在sql中减去两个查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的第一个查询向我返回值20:

my first query returns me the value 20:

    SELECT numberofseats
    from plane
    where tail number in
     ( select flighttailnumberfk
       from flight
       where departuretime between '11/29/2014' and '11/30/2014' and
             flightdepartureairportfk = 'jfk' and
             flightarrivalairport = 'mli'
     )

第二个查询返回我1:

    select count(reservationseatfk)
    from flight f, reservation r
    where f.departuretime between '11/29/2014' and '11/30/2014' and
          f.reservationflightidfk = f.flightid and r.reservationdeparturetimefk = f.departuretime

现在我的问题是我想从第二个查询中减去第一个查询,并给我答案19.我该怎么做?

Now my problem is that I want to subtract the first query from the second query and give me the answer 19. how do i do that?

推荐答案

您可以使用sub sql减去

You could use sub sql to subtract

SELECT numberofseats - ( select count(reservationseatfk)
    from flight f, reservation r
    where f.departuretime between '11/29/2014' and '11/30/2014' and
          f.reservationflightidfk = f.flightid and r.reservationdeparturetimefk = f.departuretime)
    from plane
    where tail number in
     ( select flighttailnumberfk
       from flight
       where departuretime between '11/29/2014' and '11/30/2014' and
             flightdepartureairportfk = 'jfk' and
             flightarrivalairport = 'mli'
     )

这篇关于如何在sql中减去两个查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆