0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MySQL構文(Group By)

Posted at

初めに

Group Byについて構文例を作成しました。

環境

開発環境 バージョン
MySQL ----------

Booksテーブル

Book_ID Book_Title Author_ID
1 ノルウェイの森 1
2 1Q84 1
3 舞姫 2
4 重力ピエロ 3
5 母の遺産 4

Authorsテーブル

Author_ID Author_Name
1 村上春樹
2 三浦しをん
3 伊坂幸太郎
4 川上弘美
SELECT 
    Authors.Author_ID, 
    Authors.Author_Name, 
    COUNT(Books.Book_ID) AS NumberOfBooks
FROM Authors 
LEFT JOIN Books
ON Authors.Author_ID = Books.Author_ID
GROUP BY Authors.Author_ID, Authors.Author_Name;

結果

Author_ID Author_Name NumberOfBooks
1 村上春樹 2
2 三浦しをん 1
3 伊坂幸太郎 1
4 川上弘美 1

最後に

最後まで閲覧いただきありがとうございました。
ご意見、ご指摘ありましたら、コメントお願いいたします。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?