2017-06-27 6 views
-1

Ich habe eine Tabelle, wo 4 Einträge wie folgt existiert.sql group von, obwohl es keinen Wert

class_type 

id type 
1  A 
2  B 
3  M 
4  T 

und eine andere Tabelle, in der diese Werte Fremdschlüssel sind.

id number id_class_type 
1  10   1 
2  11   1 
3  12   2  
4  13   1 
5  14   2 
6  15   3 
7  16   1 
8  17   3 

Also, was ich will, ist count (*) und die Gruppe von id_class_type aber mit all CLASS_TYPE (1,2,3,4), obwohl es ist die ID 4.

+0

Fügen Sie die vorbehalten Ergebnis auch als Texttabelle .. –

+0

Lesen Sie über Outer Joins. – mustaccio

Antwort

0

nicht vorhanden, wenn Sie nur wollen die Klasse tha Spiel können Sie innere

select a.class_type, count(*) 
    from class_type a 
    inner join table2 b on a.id = b.id_class_type 
    group by a.class_type 

sonst können Sie links JOIN verwenden beitreten

select a.class_type, count(*) 
    from class_type a 
    left join table2 b on a.id = b.id_class_type 
    group by a.class_type