Home > database >  Mysql for help
Mysql for help

Time:09-25

Table a, such as the appended drawings to statistical zc duplicate records, repeatedly refers to zc and bs, same as bs also, do not think repeat

Such as the appended drawings of the duplicate number 1

How to write a statement

CodePudding user response:

The test data
 -If not object_id (N 'Tempdb for.. # T ') is null 
Drop table # T
Go
The Create table # T (int [row], [zc] nvarchar (21), (bs) int)
Insert # T
Select 1, N 'a', 111 union all
Select 2, N 'a', 111 union all
Select 3, N 'a', 112 union all
Select 4, N 'b', 112
Go
- the end of the test data
The SELECT zc,
COUNT (1) - 1 AS the repetitions
The FROM
(SELECT DISTINCT zc, bs FROM # T) T
GROUP BY zc.

  • Related