2017-07-17 13 views
0

Ich habe eine Tabelle wie folgt aus Gruppe:durch und Zustand auf Wert einer Spalte

id tr_id type 
1  1  1   
2  1  1   
3  2  1   
4  2  2   
5  4  1   
6  4  1 
7  3  1 
8  3  2 
9  5  1 

Ich möchte alle tr_id (group by diese Spalte) erhalten, die nur type haben, und es ist nicht alle Datensätze vorhanden sind, dass type Wert ...

das Ergebnis meiner Tabelle sein muss, b e:

tr_id 
    1 

    4 

    5 

Antwort

1

Betrachtet man es in Typ Spalte

select tr_id 
from yourtable 
group by tr_id 
Having sum(distinct type) = 1 

Wenn type Spalte negative Zahlen haben kann dann

select tr_id 
from yourtable 
group by tr_id 
Having sum(type) = count(case when type = 1 then 1 end) 
0

YourModel keine negativen Zahlen ist :: select ('tr_id) -> groupBy ('tr_id') -> where ('tr_id', 1) -> get();

Verwandte Themen