Subtraction between two sql queries

前端 未结 11 2086
情歌与酒
情歌与酒 2020-12-10 00:54

I have 2 queries in MS SQL that return a number of results using the COUNT function.

I can run the the first query and get the first result and then run the other on

11条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-10 01:34

    You should be able to use subqueries for that:

    SELECT
        (SELECT COUNT(*) FROM ... WHERE ...)
      - (SELECT COUNT(*) FROM ... WHERE ...) AS Difference
    

    Just tested it:

    Difference
    -----------
    45
    
    (1 row(s) affected)
    

提交回复
热议问题