Home > database >  How to merge in SQL
How to merge in SQL

Time:11-10

When cgjh1_sjdh, of how to realize the image cgjh2_flh phase at the same time, the second line shows cgjh2_jhsl to 0

CodePudding user response:

The test data
 -DECLARE @ temp Table (ID VARCHAR (50), cloumu int) 
INSERT INTO @ temp
SELECT the 'A', 50 UNION ALL
30 UNION ALL SELECT 'B',
SELECT the 'A', 50

- after handling the case when check the first row results can
SELECT
Anderson, D,
In CASE the WHEN A.N O=1
THEN cloumu
The ELSE 0 END AS CLOUMN
The FROM (
- add the serial number field, will be ordered data grouped by ID, here you will ID replace your cgjh1_sjdh, cgjh2_flh
The SELECT ROW_NUMBER () OVER (PARTITION BY ID ORDER BY ID) AS NO, * FROM @ temp
) A


CodePudding user response:

CodePudding user response:

There are merger is essentially the case, please refer to!

CodePudding user response:

  • Related