Home > database >  [for] a database, a table inside a many-to-many data statistical problems
[for] a database, a table inside a many-to-many data statistical problems

Time:09-26

The following table data
LableA lableB lableC
1 1 1
1 2 1
2 1 1
2, 3, 1
3 1 1
1, 3, 4,
I want to get the results to lableC for dimensions, does not contain 3 in statistical lableB lableA to heavy number, the results are as follows:
LableC count
1 2

CodePudding user response:

 select lableC, count (distinct labelA) as (count) 
The from TB a
Where not the exists (select 1 from TB b where labelB=3 and a. abelA=b.l abelA)
Group by labelC
  • Related