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徹底指南書 6章 CREATE, INSERT文まとめ

Last updated at Posted at 2023-01-22

達人に学ぶSQL徹底指南書

6章:HAVING句の力

CREATE

create table SeqTbl (
  seq int,
  name varchar(50)
) charset utf8mb4;

create table Graduates (
  name varchar(50),
  income int
) charset utf8mb4;

create table Students (
    student_id int,
    dpt varchar(50),
    sbmt_date date
) charset utf8mb4;

create table TestResults (
    student_id varchar(50),
    class varchar(50),
    sex varchar(50),
    score int
) charset utf8mb4;

create table Teams (
    member varchar(50),
    team_id int,
    status varchar(50)
) charset utf8mb4;

create table Items (
    item varchar(50)
) charset utf8mb4;

create table ShopItems (
    shop varchar(50),
    item varchar(50)
) charset utf8mb4;

create table Materials (
    center varchar(50),
    receive_date date,
    material varchar(50)
) charset utf8mb4;

INSERT

insert into Teams values 
('ジョー', 1, '待機'),
('ケン', 1, '出動中'),
('ミック', 1, '待機'),
('カレン', 2, '出動中'),
('キース', 2, '休暇'),
('ジャン', 3, '待機'),
('ハート', 3, '待機'),
('ディック', 3, '待機'),
('ベス', 4, '待機'),
('アレン', 5, '出動中'),
('ロバート', 5, '休暇'),
('ケーガン', 5, '待機');

insert into SeqTbl values
(1, 'ディック'),
(2, 'アン'),
(3, 'ライル'),
(5, 'カー'),
(6, 'マリー'),
(8, 'ベン');

insert into Graduates values
('サンプソン', 400000),
('マイク', 30000),
('ホワイト', 20000),
('アーノルド', 20000),
('スミス', 20000),
('ロレンス', 15000),
('ハドソン', 15000),
('ケント', 10000),
('ベッカー', 10000),
('スコット', 10000);

insert into Students values
(100, '理学部', '2018-10-10'),
(101, '理学部', '2018-09-22'),
(102, '文学部', null),
(103, '文学部', '2018-09-10'),
(200, '文学部', '2018-09-22'),
(201, '工学部', null),
(202, '経済学部', '2018-09-25');

insert into TestResults values
('001', 'A', '男', 100),
('002', 'A', '女', 100),
('003', 'A', '女', 49),
('004', 'A', '男', 30),
('005', 'B', '女', 100),
('006', 'B', '男', 92),
('007', 'B', '男', 80),
('008', 'B', '男', 80),
('009', 'B', '女', 10),
('010', 'C', '男', 92),
('011', 'C', '男', 80),
('012', 'C', '女', 21),
('013', 'D', '女', 100),
('014', 'D', '女', 0),
('015', 'D', '女', 0);

insert into Items values
('ビール'),
('紙オムツ'),
('自転車');

insert into ShopItems values
('仙台', 'ビール'),
('仙台', '紙オムツ'),
('仙台', '自転車'),
('仙台', 'カーテン'),
('東京', 'ビール'),
('東京', '紙オムツ'),
('東京', '自転車'),
('大阪', 'テレビ'),
('大阪', '紙オムツ'),
('大阪', '自転車');

insert into Materials values
('東京', '2018-04-01', '錫'),
('東京', '2018-04-12', '亜鉛'),
('東京', '2018-05-17', 'アルミニウム'),
('東京', '2018-05-20', '亜鉛'),
('大阪', '2018-04-20', '銅'),
('大阪', '2018-04-22', 'ニッケル'),
('大阪', '2018-04-29', '鉛'),
('名古屋', '2018-03-15', 'チタン'),
('名古屋', '2018-04-01', '炭素鋼'),
('名古屋', '2018-04-24', '炭素鋼'),
('名古屋', '2018-05-02', 'マグネシウム'),
('名古屋', '2018-05-10', 'チタン'),
('福岡', '2018-05-10', '亜鉛'),
('福岡', '2018-05-28', '錫');
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?