How can I subtract two queries in sql?

manohjay

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'
     )

and my second query returns me 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

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?

hkutluay

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'
     )

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How Can I merge these two Access Sql queries

From Dev

How can I combine these two SQL queries into a single query?

From Dev

How can I subtract two NSUInteger variables?

From Dev

Mysql - How can I subtract the number of rows returned by 2 queries

From Dev

Can I combine these two SQL queries into one?

From Dev

How I can Make this Subtract in SQL

From Dev

How can I subtract two row's values within same column using sql query?

From Dev

How can I subtract two row's values within same column using a SQL query?

From Dev

How can I combine these two queries into one?

From Dev

How can I combine these two queries?

From Dev

How to Subtract the result of two Django Queries?

From Dev

How i can i subtract two selected columns in the same query?

From Dev

how can I add (subtract, etc.) two numbers with bash?

From Dev

Bash: How can I subtract two time strings using bash?

From Dev

How can I separate SQL queries

From Dev

How can I join 3 SQL queries

From Dev

How can I write two update queries in single stored procedure in SQL Server 2008

From Dev

SQL Server CE : how can I combine results of two queries into one row?

From Dev

How can I join two join queries into one?

From Dev

How can I use a join to combine these two queries?

From Dev

How can I make two queries at once in MongoDB

From Dev

How can I combine these two queries? (where in clause)?

From Dev

How can I populate one UITableView with two queries?

From Dev

How can I combine two queries opencmis alfresco

From Dev

How can I show and pagination two queries in the laravel blade?

From Dev

How can I convert these two queries in a loop into a single JOINed query?

From Dev

How can I populate one UITableView with two queries?

From Dev

How can I combine two queries opencmis alfresco

From Dev

How can I join these two select queries into one query?

Related Related

  1. 1

    How Can I merge these two Access Sql queries

  2. 2

    How can I combine these two SQL queries into a single query?

  3. 3

    How can I subtract two NSUInteger variables?

  4. 4

    Mysql - How can I subtract the number of rows returned by 2 queries

  5. 5

    Can I combine these two SQL queries into one?

  6. 6

    How I can Make this Subtract in SQL

  7. 7

    How can I subtract two row's values within same column using sql query?

  8. 8

    How can I subtract two row's values within same column using a SQL query?

  9. 9

    How can I combine these two queries into one?

  10. 10

    How can I combine these two queries?

  11. 11

    How to Subtract the result of two Django Queries?

  12. 12

    How i can i subtract two selected columns in the same query?

  13. 13

    how can I add (subtract, etc.) two numbers with bash?

  14. 14

    Bash: How can I subtract two time strings using bash?

  15. 15

    How can I separate SQL queries

  16. 16

    How can I join 3 SQL queries

  17. 17

    How can I write two update queries in single stored procedure in SQL Server 2008

  18. 18

    SQL Server CE : how can I combine results of two queries into one row?

  19. 19

    How can I join two join queries into one?

  20. 20

    How can I use a join to combine these two queries?

  21. 21

    How can I make two queries at once in MongoDB

  22. 22

    How can I combine these two queries? (where in clause)?

  23. 23

    How can I populate one UITableView with two queries?

  24. 24

    How can I combine two queries opencmis alfresco

  25. 25

    How can I show and pagination two queries in the laravel blade?

  26. 26

    How can I convert these two queries in a loop into a single JOINed query?

  27. 27

    How can I populate one UITableView with two queries?

  28. 28

    How can I combine two queries opencmis alfresco

  29. 29

    How can I join these two select queries into one query?

HotTag

Archive