1
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 3 years have passed since last update.

メモ②-SELECT文の基本-

Last updated at Posted at 2020-02-26

【仮定・予備知識】
「->」←これはEnterキーで改行したことを表す記号。
MySQLでは、「;」を入力しない限り、いくらでも改行することができる。
また、「SELECT 」の「」印は、「すべての項目」を扱いたいときに使うもの。

①練習用データベース「company」のemployeeテーブルを、コード順に並び替えたいとき

昇順に並べる場合↓
MariaDB [company]> SELECT *
-> FROM
-> tbl_employee;
もしくは
MariaDB [company]> SELECT *
-> FROM
-> tbl_employee
-> ORDER BY
-> code ASC;

降順に並べる場合↓
MariaDB [company]> SELECT *
-> FROM
-> tbl_employee
-> ORDER BY
-> code DESC;

②companyデータベースのemployeeテーブルから「伊藤英樹」を抽出する場合
MariaDB [company]> SELECT *
-> FROM
-> tbl_employee
-> WHERE
-> name = "伊藤英樹";

③companyデータベースのemployeeテーブルから血液型A型の人を抽出する場合
MariaDB [company]> SELECT *
-> FROM
-> tbl_employee
-> WHERE
-> blood = "A";

④companyデータベースのemployeeテーブルから基本給(basic_salary)が23万円以上の人を抽出する
MariaDB [company]> SELECT *
-> FROM
-> tbl_employee
-> WHERE
-> basic_salary >= 230000
-> ORDER BY
-> basic_salary ASC;

⑤companyデータベースのemployeeテーブルからコード(code)と基本給(basic_salary)だけを表示し、
基本給が23万円以上の人だけを抽出する
MariaDB [company]> SELECT
-> code,basic_salary
-> FROM
-> tbl_employee
-> WHERE
-> basic_salary >= 230000
-> ORDER BY
-> basic_salary ASC;

・・・③へ続く

1
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
1
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?