1 Usetest12 SelectAddress_district,COUNT(address_district) asTotal fromHr_personal_testGroup byAddress_district withRollup;3 Create TableTest1 (IDint);4 Create TableTest2 (numint);5 6 --1 1 (2) (1,4)7 --INSERT INTO TEST1 Select 1 Union SELECT 2 Union SELECT 38 --INSERT INTO TEST2 Select 1 Union Select 49 Ten --Select ID from test1 except select num from test2;-------return result 2,3 One A - Delete fromtest1; - Delete fromtest2; the --2 1 (2) (1,2,3,4) - --INSERT INTO TEST1 Select 1 Union select 2 - --INSERT INTO TEST2 Select 1 Union SELECT 2 Union SELECT 3 Union Select 4 - --Select ID from test1 except select num from test2;--------return result no + - Delete fromtest1; + Delete fromtest2; A --3 1 (2) (3,4) at Insert intoTest1Select 1 Union Select 2 - Insert intoTest2Select 3 Union Select 4 - SelectId fromTest1except SelectNum fromTest2--------Return Results - - Delete fromtest1; - Delete fromtest2; in --4 1 (2 ) - Insert intoTest1Select 1 Union Select 2 Union Select 3 to Insert intoTest2Select 1 Union Select 2 + SelectId fromTest1except SelectNum fromTest2--------Return Results 3
Create TableTest1 (IDint, namenvarchar( -))Create TableTest2 (IDint, postnvarchar(4))Insert intoTest1 (name)Values('a'),('b'),('b'),('C')Insert intoTest2 (POST)Values('a')SelectName fromTest1except SelectPost fromtest2--------back to B,cSelectName fromTest1whereName not inch(SelectPost fromTEST2)---------return to B,b,c
Thus, the following points can be drawn:
1. The except operator compares the data, not the fields with the same field names in different tables.
2. Except operator in a nutshell: Find data in the left table that is not present in the right table. Use a set to represent a a-a B rather than (A and B)-(A-B).
3, the except operator is going to be heavy, not in.
about the except in SQL