How do I 'subtract' sql tables?

后端 未结 14 1961
死守一世寂寞
死守一世寂寞 2020-12-05 13:12

Its not really a subtraction I\'m looking for. And I know its not a union or intersection... I have been given a long and complex stored procedure that returns a table of

相关标签:
14条回答
  • 2020-12-05 14:17

    if you are substracting a percentage and updating a table use this

    UPDATE `TABLENAME` SET `COLUMNNAME` = (50 / 100) * `COLUMNNAME`;
    

    please note that the (50 / 100) is for 50% so in this case this query will discount 50% from the total value of the row!

    0 讨论(0)
  • 2020-12-05 14:18

    You can also do this with the NOT IN clause

    For example, assuming the stored procedures have given you table variables called @AllDocuments and @ActiveDocuments and each document has an identifier column called DocId

    SELECT * FROM @AllDocuments 
    WHERE DocId NOT IN 
        (SELECT DocId FROM @ActiveDocuments)
    

    Adapt this as appropriate to match your table / column names.

    0 讨论(0)
提交回复
热议问题