This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE blog_entry ( | |
written_by VARCHAR(32) NOT NULL, | |
entry_date DATE NOT NULL, | |
favs INT NOT NULL | |
) | |
; | |
ALTER TABLE blog_entry ADD CONSTRAINT UNIQUE (written_by, entry_date) | |
; | |
INSERT INTO blog_entry VALUES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ************************** | |
ランキングを求める : MySQL | |
************************** */ | |
create table products ( | |
name varchar(32) not null, | |
price int not null | |
) | |
; | |
insert into products values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create temporary table lovers | |
select * from ( | |
select 'shidou' school, 'ギイ' pair1, '託生' pair2, TRUE is_coupled | |
union all select 'shidou' school, '三洲' pair1, '真行寺' pair2, TRUE is_coupled | |
union all select NULL school, '赤池' pair1, NULL pair2, FALSE is_coupled | |
) X | |
; | |
select * from lovers | |
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table emp ( | |
id int primary key auto_increment, | |
name varchar(32) not null unique, salary int not null | |
) | |
; | |
insert into emp (name, salary) values ('foo', 250000), ('bar', 320000), ('baz', 130000); | |
select | |
id, name, salary old_salary, | |
case |