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.

達人に学ぶSQL徹底指南書 1章 CREATE, INSERT文まとめ

Last updated at Posted at 2023-01-07

達人に学ぶSQL徹底指南書
1章:CASE 式のススメ

本文中に書かれている内容を実行したかったので、自分用にメモ。
※本のサンプルと行の順序が異なる場合あり

CREATE

CREATE TABLE CourseMaster (
  course_id int,
  course_name varchar(255)
) charset utf8mb4;

CREATE TABLE OpenCourses (
  month varchar(255),
  course_id int
) charset utf8mb4;

CREATE TABLE StudentClub (
  std_id varchar(255),
  club_id int,
  club_name varchar(255),
  main_club_flg varchar(1)
) charset utf8mb4;

CREATE TABLE PopTbl2 (
  pref_name varchar(255),
  sex int,
  population int
) charset utf8mb4;

INSERT

insert into StudentClub values
(100, 1, '野球', 'Y'),
(100, 2, '吹奏楽', 'N'),
(200, 2, '吹奏楽', 'N'),
(200, 3, 'バドミントン', 'Y'),
(200, 4, 'サッカー', 'N'),
(300, 4, 'サッカー', 'N'),
(400, 5, '水泳', 'N'),
(500, 6, '囲碁', 'N');


insert into CourseMaster values 
(1, '経理入門'),
(2, '財務知識'),
(3, '簿記検定開講講座'),
(4, '税理士');

insert into OpenCourses values
(201806, 1),
(201806, 3),
(201806, 4),
(201807, 4),
(201808, 2),
(201808, 4);

INSERT INTO PopTbl2 VALUES 
('tokushima', '1', '60'),
('tokushima', '2', '40'),
('kagawa', '1', '100'),
('kagawa', '2', '100'),
('ehime', '1', '100'),
('ehime', '2', '50'),
('kouti', '1', '100'),
('kouti', '2', '100'),
('hukuoka', '1', '100'),
('hukuoka', '2', '200'),
('saga', '1', '20'),
('saga', '2', '80'),
('nagasaki', '1', '125'),
('nagasaki', '2', '125'),
('tokyo', '1', '250'),
('tokyo', '2', '150');
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?