2017-06-27 10 views
-1

私はこのような4つのエントリが存在するテーブルを持っています。値がありませんが、SQLのグループ

class_type 

id type 
1  A 
2  B 
3  M 
4  T 

これらの値は外部キーです。

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 

だから私が欲しいのはあなただけしたい場合は、idに4

+0

もテキストテーブルとして除外結果を含める参加使用することができます

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 

に参加します.. –

+0

外部結合について読んでください。 – mustaccio

答えて

0

が存在しないがid_class_typeではなく、すべてのCLASS_TYPE(1,2,3,4)とCOUNT(*)とグループでありますあなたは、内側に使用できるクラス股関節の試合は、そうしないと、左

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 
関連する問題