完了済
This commit is contained in:
309
Answers/Q3_DataDef.sql
Normal file
309
Answers/Q3_DataDef.sql
Normal file
@@ -0,0 +1,309 @@
|
|||||||
|
----------------------------------------
|
||||||
|
----------------------------------------
|
||||||
|
--<EFBFBD>e<EFBFBD><EFBFBD><EFBFBD>}<EFBFBD>X<EFBFBD>^
|
||||||
|
|
||||||
|
--<EFBFBD>x<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʃ}<EFBFBD>X<EFBFBD>^
|
||||||
|
CREATE TABLE pay_div_m (
|
||||||
|
pay_div_cd CHAR(5) NOT NULL COMMENT '<EFBFBD>x<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ރR<EFBFBD>[<5B>h',
|
||||||
|
pay_div_nm VARCHAR(50) NOT NULL COMMENT '<EFBFBD>x<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ޖ<EFBFBD>',
|
||||||
|
PRIMARY KEY (pay_div_cd)
|
||||||
|
)
|
||||||
|
COMMENT '<EFBFBD>x<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʃ}<7D>X<EFBFBD>^';
|
||||||
|
INSERT INTO pay_div_m VALUES ('PY001', '<EFBFBD>N<EFBFBD><EFBFBD><EFBFBD>W<EFBFBD>b<EFBFBD>g<EFBFBD>J<EFBFBD>[<5B>h');
|
||||||
|
INSERT INTO pay_div_m VALUES ('PY002', '<EFBFBD><EFBFBD><EFBFBD>s<EFBFBD>U<EFBFBD><EFBFBD>');
|
||||||
|
INSERT INTO pay_div_m VALUES ('PY003', '<EFBFBD>R<EFBFBD><EFBFBD><EFBFBD>r<EFBFBD>j<EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
|
||||||
|
INSERT INTO pay_div_m VALUES ('PY004', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
|
||||||
|
|
||||||
|
--<EFBFBD><EFBFBD><EFBFBD>ʃ}<EFBFBD>X<EFBFBD>^
|
||||||
|
CREATE TABLE gender_m (
|
||||||
|
gender_cd CHAR(2) NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>ʃR<EFBFBD>[<5B>h',
|
||||||
|
gender_div_nm VARCHAR(50) NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>ʕ<EFBFBD><EFBFBD>ޖ<EFBFBD>',
|
||||||
|
PRIMARY KEY (gender_cd)
|
||||||
|
)
|
||||||
|
COMMENT '<EFBFBD><EFBFBD><EFBFBD>ʃ}<7D>X<EFBFBD>^';
|
||||||
|
INSERT INTO gender_m VALUES ('J0', '<EFBFBD>j<EFBFBD><EFBFBD>');
|
||||||
|
INSERT INTO gender_m VALUES ('J1', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
|
||||||
|
INSERT INTO gender_m VALUES ('J9', '<EFBFBD><EFBFBD><EFBFBD>̑<EFBFBD>');
|
||||||
|
|
||||||
|
--<EFBFBD>N<EFBFBD><EFBFBD><EFBFBD>W<EFBFBD>b<EFBFBD>g<EFBFBD>J<EFBFBD>[<EFBFBD>h<EFBFBD><EFBFBD><EFBFBD>ރ}<EFBFBD>X<EFBFBD>^
|
||||||
|
CREATE TABLE credit_div_m (
|
||||||
|
credit_div_cd CHAR(5) NOT NULL COMMENT '<EFBFBD>J<EFBFBD>[<5B>h<EFBFBD><68><EFBFBD>ރR<DE83>[<5B>h',
|
||||||
|
credit_div_nm VARCHAR(50) NOT NULL COMMENT '<EFBFBD>J<EFBFBD>[<5B>h<EFBFBD><68><EFBFBD>ޖ<EFBFBD>',
|
||||||
|
PRIMARY KEY (credit_div_cd)
|
||||||
|
)
|
||||||
|
COMMENT '<EFBFBD>N<EFBFBD><EFBFBD><EFBFBD>W<EFBFBD>b<EFBFBD>g<EFBFBD>J<EFBFBD>[<5B>h<EFBFBD><68><EFBFBD>ރ}<7D>X<EFBFBD>^';
|
||||||
|
INSERT INTO credit_div_m VALUE ('CD001', 'VISA');
|
||||||
|
INSERT INTO credit_div_m VALUE ('CD002', 'JCB');
|
||||||
|
INSERT INTO credit_div_m VALUE ('CD003', 'Master');
|
||||||
|
INSERT INTO credit_div_m VALUE ('CD004', 'AMERICAN EXPRESS');
|
||||||
|
|
||||||
|
--<EFBFBD><EFBFBD><EFBFBD>i<EFBFBD><EFBFBD><EFBFBD>ރ}<EFBFBD>X<EFBFBD>^
|
||||||
|
CREATE TABLE goods_div_m (
|
||||||
|
goods_div_cd CHAR(5) NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>i<EFBFBD><EFBFBD><EFBFBD>ރR<EFBFBD>[<5B>h',
|
||||||
|
goods_div_nm VARCHAR(50) NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>i<EFBFBD><EFBFBD><EFBFBD>ޖ<EFBFBD>',
|
||||||
|
PRIMARY KEY (goods_div_cd)
|
||||||
|
)
|
||||||
|
COMMENT '<EFBFBD><EFBFBD><EFBFBD>i<EFBFBD><EFBFBD><EFBFBD>ރ}<7D>X<EFBFBD>^';
|
||||||
|
INSERT INTO goods_div_m VALUE ('K0001', '<EFBFBD><EFBFBD><EFBFBD>p<EFBFBD>i');
|
||||||
|
INSERT INTO goods_div_m VALUE ('K0002', '<EFBFBD>p<EFBFBD>\<5C>R<EFBFBD><52><EFBFBD>E<EFBFBD>I<EFBFBD>t<EFBFBD>B<EFBFBD>X<EFBFBD>p<EFBFBD>i');
|
||||||
|
INSERT INTO goods_div_m VALUE ('K0003', '<EFBFBD>X<EFBFBD>|<7C>[<5B>c<EFBFBD><63><EFBFBD>A<EFBFBD>E<EFBFBD>g<EFBFBD>h<EFBFBD>A');
|
||||||
|
INSERT INTO goods_div_m VALUE ('K0004', '<EFBFBD>J<EFBFBD>[<5B>p<EFBFBD>i');
|
||||||
|
INSERT INTO goods_div_m VALUE ('K0005', '<EFBFBD>H<EFBFBD><EFBFBD><EFBFBD>i');
|
||||||
|
INSERT INTO goods_div_m VALUE ('K0006', '<EFBFBD>Ɠd');
|
||||||
|
INSERT INTO goods_div_m VALUE ('K0007', '<EFBFBD>t<EFBFBD>@<40>b<EFBFBD>V<EFBFBD><56><EFBFBD><EFBFBD>');
|
||||||
|
INSERT INTO goods_div_m VALUE ('K0008', '<EFBFBD><EFBFBD><EFBFBD>y');
|
||||||
|
|
||||||
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ń}<EFBFBD>X<EFBFBD>^
|
||||||
|
CREATE TABLE tax_m (
|
||||||
|
app_date DATE NOT NULL COMMENT '<EFBFBD>K<EFBFBD>p<EFBFBD>N<EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||||
|
tax_rate INT NOT NULL DEFAULT 0 COMMENT '<EFBFBD>ŗ<EFBFBD><EFBFBD>i<EFBFBD><EFBFBD><EFBFBD>j',
|
||||||
|
PRIMARY KEY (app_date)
|
||||||
|
)
|
||||||
|
COMMENT '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ń}<7D>X<EFBFBD>^';
|
||||||
|
INSERT INTO tax_m VALUE ('1989-4-1', 3);
|
||||||
|
INSERT INTO tax_m VALUE ('1997-4-1', 5);
|
||||||
|
INSERT INTO tax_m VALUE ('2014-4-1', 8);
|
||||||
|
INSERT INTO tax_m VALUE ('2019-10-1', 10);
|
||||||
|
|
||||||
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>X<EFBFBD>e<EFBFBD>[<EFBFBD>^<EFBFBD>X
|
||||||
|
CREATE TABLE order_sts_m (
|
||||||
|
sts_cd CHAR(5) NOT NULL COMMENT '<EFBFBD>X<EFBFBD>e<EFBFBD>[<5B>^<5E>X<EFBFBD>R<EFBFBD>[<5B>h',
|
||||||
|
sts VARCHAR(50) NOT NULL COMMENT '<EFBFBD>X<EFBFBD>e<EFBFBD>[<5B>^<5E>X',
|
||||||
|
PRIMARY KEY (sts_cd)
|
||||||
|
)
|
||||||
|
COMMENT '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>X<EFBFBD>e<EFBFBD>[<5B>^<5E>X';
|
||||||
|
INSERT INTO order_sts_m VALUE ('ST001', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
|
||||||
|
INSERT INTO order_sts_m VALUE ('ST002', '<EFBFBD><EFBFBD><EFBFBD>ב<EFBFBD>');
|
||||||
|
INSERT INTO order_sts_m VALUE ('ST003', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
|
||||||
|
INSERT INTO order_sts_m VALUE ('ST004', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
|
||||||
|
INSERT INTO order_sts_m VALUE ('ST010', '<EFBFBD><EFBFBD><EFBFBD>q<EFBFBD>l<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
|
||||||
|
INSERT INTO order_sts_m VALUE ('ST999', '<EFBFBD>L<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Z<EFBFBD><EFBFBD>');
|
||||||
|
|
||||||
|
----------------------------------------
|
||||||
|
----------------------------------------
|
||||||
|
|
||||||
|
--<EFBFBD>ڋq<EFBFBD>}<EFBFBD>X<EFBFBD>^
|
||||||
|
CREATE TABLE user_m (
|
||||||
|
user_id CHAR(10) NOT NULL COMMENT '<EFBFBD>ڋqID',
|
||||||
|
user_f_nm VARCHAR(50) NOT NULL COMMENT '<EFBFBD><EFBFBD>',
|
||||||
|
user_f_nm_kn VARCHAR(50) NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>J<EFBFBD>i',
|
||||||
|
user_nm VARCHAR(50) NOT NULL COMMENT '<EFBFBD><EFBFBD>',
|
||||||
|
user_nm_kn VARCHAR(50) NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>J<EFBFBD>i',
|
||||||
|
user_birth DATE NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>N<EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||||
|
gender_cd CHAR(2) NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||||
|
mail_address VARCHAR(50) NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>[<5B><><EFBFBD>A<EFBFBD>h<EFBFBD><68><EFBFBD>X',
|
||||||
|
user_post_no CHAR(8) NOT NULL COMMENT '<EFBFBD>X<EFBFBD>֔ԍ<EFBFBD>',
|
||||||
|
user_prefecture_nm VARCHAR(4) NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||||
|
user_municipality_nm VARCHAR(50) NOT NULL COMMENT '<EFBFBD>s<EFBFBD>撬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||||
|
user_city_nm VARCHAR(50) NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>於',
|
||||||
|
user_address VARCHAR(50) NOT NULL COMMENT '<EFBFBD>Z<EFBFBD><EFBFBD>',
|
||||||
|
user_building_nm VARCHAR(50) COMMENT '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||||
|
user_tel_nm VARCHAR(50) NOT NULL COMMENT '<EFBFBD>d<EFBFBD>b<EFBFBD>ԍ<EFBFBD>',
|
||||||
|
user_passwd VARCHAR(50) NOT NULL COMMENT '<EFBFBD>p<EFBFBD>X<EFBFBD><EFBFBD><EFBFBD>[<5B>h',
|
||||||
|
PRIMARY KEY (user_id),
|
||||||
|
FOREIGN KEY (gender_cd) REFERENCES gender_m(gender_cd)
|
||||||
|
)
|
||||||
|
COMMENT '<EFBFBD>ڋq<EFBFBD>}<7D>X<EFBFBD>^';
|
||||||
|
INSERT INTO user_m VALUE ('CU00000001', '<EFBFBD>R<EFBFBD>c', '<EFBFBD><EFBFBD><EFBFBD>}<7D>_', '<EFBFBD><EFBFBD>', '<EFBFBD>n<EFBFBD>W<EFBFBD><EFBFBD>', '1973-06-06', 'J0', 'h.yamada@hoge.com', '140-0014', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>s', '<EFBFBD>i<EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>-<2D><>', '<EFBFBD>}<7D><><EFBFBD>V<EFBFBD><56><EFBFBD><EFBFBD><EFBFBD>P<EFBFBD>R<EFBFBD>X<EFBFBD>X', '090-xxxx-xxxx', 'hX8UEzE8');
|
||||||
|
INSERT INTO user_m VALUE ('CU00000002', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<EFBFBD>^<5E>J<EFBFBD>n<EFBFBD>V', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<EFBFBD>^<5E>c<EFBFBD><63>', '1970-11-10', 'J0', 't.takahashi@hoge.com', '230-0063', '<EFBFBD>_<EFBFBD>ސ쌧', '<EFBFBD><EFBFBD><EFBFBD>l<EFBFBD>s<EFBFBD>ߌ<EFBFBD><EFBFBD><EFBFBD>', '<EFBFBD>ߌ<EFBFBD>', '<EFBFBD>~-<2D>~<7E>~', NULL, '090-xxxx-xxxx', 'UQQA6B3R');
|
||||||
|
INSERT INTO user_m VALUE ('CU00000003', '<EFBFBD><EFBFBD><EFBFBD>}', '<EFBFBD>}<7D>G<EFBFBD>_', '<EFBFBD>y', '<EFBFBD>W<EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '1975-1-3', 'J0', 'j.maeda@hoge.com', '333-0823', '<EFBFBD><EFBFBD><EFBFBD>ʌ<EFBFBD>', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>s', '<EFBFBD>ΐ_', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>-<2D><>', NULL, '090-yyyy-1234', 'UDHWnLLk');
|
||||||
|
INSERT INTO user_m VALUE ('CU00000004', '<EFBFBD>O<EFBFBD><EFBFBD>', '<EFBFBD>~<7E><><EFBFBD>P', '<EFBFBD>͉<EFBFBD>', '<EFBFBD>V<EFBFBD><EFBFBD><EFBFBD>E<EFBFBD>X<EFBFBD>P', '1970-10-10', 'J0', 's.miyake@hoge.com', '273-0031', '<EFBFBD><EFBFBD><EFBFBD>t<EFBFBD><EFBFBD>', '<EFBFBD>D<EFBFBD><EFBFBD><EFBFBD>s', '<EFBFBD><EFBFBD><EFBFBD>D', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>-<2D><>', '<EFBFBD>A<EFBFBD>p<EFBFBD>[<5B>g<EFBFBD>P<EFBFBD>O<EFBFBD>P', '090-yyyy-5678', 'E2QGZNzw');
|
||||||
|
INSERT INTO user_m VALUE ('CU00000005', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<EFBFBD>X<EFBFBD>Y<EFBFBD><EFBFBD><EFBFBD>g', '<EFBFBD>I<EFBFBD><EFBFBD>', '<EFBFBD><EFBFBD><EFBFBD>E<EFBFBD>C<EFBFBD>`', '1969-1-13', 'J0', 'y.suzumoto@hoge.com', '321-0207', '<EFBFBD>Ȗ،<EFBFBD>', '<EFBFBD><EFBFBD><EFBFBD>s<EFBFBD><EFBFBD><EFBFBD>S<EFBFBD>p<EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<EFBFBD>k<EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<EFBFBD>~<7E>~<7E>~<7E>~', NULL, '090-1234-xxxx', 'DZy5qadL');
|
||||||
|
|
||||||
|
|
||||||
|
--<EFBFBD>N<EFBFBD><EFBFBD><EFBFBD>W<EFBFBD>b<EFBFBD>g<EFBFBD>J<EFBFBD>[<EFBFBD>h
|
||||||
|
CREATE TABLE credit_card_t (
|
||||||
|
user_id CHAR(10) NOT NULL COMMENT '<EFBFBD>ڋqID',
|
||||||
|
credit_div_cd CHAR(5)NOT NULL COMMENT '<EFBFBD>J<EFBFBD>[<5B>h<EFBFBD><68><EFBFBD>ރR<DE83>[<5B>h',
|
||||||
|
credit_no CHAR(19) NOT NULL COMMENT '<EFBFBD>J<EFBFBD>[<5B>h<EFBFBD>ԍ<EFBFBD>',
|
||||||
|
credit_nm VARCHAR(50) NOT NULL COMMENT '<EFBFBD>J<EFBFBD>[<5B>h<EFBFBD><68><EFBFBD>`',
|
||||||
|
validated_month CHAR(2) NOT NULL COMMENT '<EFBFBD>L<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||||
|
validated_year CHAR(4) NOT NULL COMMENT '<EFBFBD>L<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>N',
|
||||||
|
sc_cd CHAR(3) NOT NULL COMMENT '<EFBFBD>V<EFBFBD>[<5B>N<EFBFBD><4E><EFBFBD>b<EFBFBD>h<EFBFBD>R<EFBFBD>[<5B>h',
|
||||||
|
PRIMARY KEY (user_id),
|
||||||
|
FOREIGN KEY (user_id) REFERENCES user_m(user_id),
|
||||||
|
FOREIGN KEY (credit_div_cd) REFERENCES credit_div_m(credit_div_cd)
|
||||||
|
)
|
||||||
|
COMMENT '<EFBFBD>N<EFBFBD><EFBFBD><EFBFBD>W<EFBFBD>b<EFBFBD>g<EFBFBD>J<EFBFBD>[<5B>h';
|
||||||
|
INSERT INTO credit_card_t VALUE ('CU00000001', 'CD001', 'xxxx-xxxx-xxxx-xxxx', 'HAJIME YAMADA', '03', '2017', 'xxx');
|
||||||
|
INSERT INTO credit_card_t VALUE ('CU00000005', 'CD001', 'xxxx-xxxx-xxxx-xxxx', 'YUICHI SUZUMOTO', '03', '2016', 'xxx');
|
||||||
|
|
||||||
|
--<EFBFBD><EFBFBD><EFBFBD>O<EFBFBD>C<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
CREATE TABLE login_hist_t (
|
||||||
|
user_id VARCHAR(10) NOT NULL COMMENT '<EFBFBD>ڋqID',
|
||||||
|
sfx CHAR(1) NOT NULL COMMENT 'SFX',
|
||||||
|
login_datetime DATETIME NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>O<EFBFBD>C<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||||
|
conn_ip CHAR(15) NOT NULL COMMENT '<EFBFBD>ڑ<EFBFBD><EFBFBD><EFBFBD>IP',
|
||||||
|
term_info VARCHAR(50) NOT NULL COMMENT '<EFBFBD>[<5B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||||
|
PRIMARY KEY (login_datetime),
|
||||||
|
FOREIGN KEY (user_id) REFERENCES user_m(user_id)
|
||||||
|
)
|
||||||
|
COMMENT '<EFBFBD><EFBFBD><EFBFBD>O<EFBFBD>C<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
|
||||||
|
INSERT INTO login_hist_t VALUE ('CU00000001', '1', '2014-10-1 10:00:00', 'xxx.xxx.xxx.xxx', '<EFBFBD>X<EFBFBD>}<7D>[<5B>g<EFBFBD>t<EFBFBD>H<EFBFBD><48>');
|
||||||
|
|
||||||
|
----------------------------------------
|
||||||
|
----------------------------------------
|
||||||
|
|
||||||
|
--<EFBFBD><EFBFBD><EFBFBD>i<EFBFBD>}<EFBFBD>X<EFBFBD>^
|
||||||
|
CREATE TABLE goods_m (
|
||||||
|
goods_id CHAR(10) NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>iID',
|
||||||
|
goods_nm VARCHAR(50) NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>i<EFBFBD><EFBFBD>',
|
||||||
|
goods_maker VARCHAR(50) NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>[<5B>J<EFBFBD>[',
|
||||||
|
goods_div_cd CHAR(5) NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>i<EFBFBD><EFBFBD><EFBFBD>ރR<EFBFBD>[<5B>h',
|
||||||
|
handling_date DATE NOT NULL COMMENT '<EFBFBD>戵<EFBFBD>J<EFBFBD>n<EFBFBD><EFBFBD>',
|
||||||
|
goods_price INT NOT NULL DEFAULT 0 COMMENT '<EFBFBD><EFBFBD><EFBFBD>i',
|
||||||
|
goods_cost INT NOT NULL DEFAULT 0 COMMENT '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||||
|
PRIMARY KEY (goods_id),
|
||||||
|
FOREIGN KEY (goods_div_cd) REFERENCES goods_div_m(goods_div_cd)
|
||||||
|
)
|
||||||
|
COMMENT '<EFBFBD><EFBFBD><EFBFBD>i<EFBFBD>}<7D>X<EFBFBD>^';
|
||||||
|
INSERT INTO goods_m VALUE ('ITM0000001', 'EIZO FlexScan 27<32>C<EFBFBD><43><EFBFBD>`<60>J<EFBFBD><4A><EFBFBD>[<5B>t<EFBFBD><74><EFBFBD><EFBFBD><EFBFBD>j<EFBFBD>^<5E>[', 'EIZO', 'K0002', '2012-8-24', 79110, 40000);
|
||||||
|
INSERT INTO goods_m VALUE ('ITM0000002', '<EFBFBD>T<EFBFBD>b<EFBFBD>J<EFBFBD>[ <20><><EFBFBD>{<7B><><EFBFBD>\ <20>ԍ<EFBFBD><D48D><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>v<EFBFBD><76><EFBFBD>J<EFBFBD><4A><EFBFBD>j<EFBFBD>t<EFBFBD>H<EFBFBD>[<5B><>', 'adidas(<28>A<EFBFBD>f<EFBFBD>B<EFBFBD>_<EFBFBD>X)', 'K0003', '2014-3-4', 12915, 2000);
|
||||||
|
INSERT INTO goods_m VALUE ('ITM0000003', '<EFBFBD><EFBFBD><EFBFBD>C<EFBFBD>R<EFBFBD>b<EFBFBD>v <20>ӂƂ<D382><C682>N<EFBFBD><4E><EFBFBD>[<5B>i<EFBFBD>[ (<28>p<EFBFBD>[<5B><><EFBFBD>z<EFBFBD><7A><EFBFBD>C<EFBFBD>g)', '<EFBFBD><EFBFBD><EFBFBD>C<EFBFBD>R<EFBFBD>b<EFBFBD>v', 'K0006', '2013-9-17', 24500, 12000);
|
||||||
|
INSERT INTO goods_m VALUE ('ITM0000004', '<EFBFBD>u<EFBFBD><EFBFBD><EFBFBD>K<EFBFBD><EFBFBD> <20>A<EFBFBD>N<EFBFBD>A<EFBFBD>v<EFBFBD>[<5B><><EFBFBD>I<EFBFBD><49> <20>}<7D><><EFBFBD><EFBFBD> EDT SP 100ml', '<EFBFBD>u<EFBFBD><EFBFBD><EFBFBD>K<EFBFBD><EFBFBD>', 'K0007', '2010-3-3', 3712, 1500);
|
||||||
|
INSERT INTO goods_m VALUE ('ITM0000005', '<EFBFBD>}<7D>W<EFBFBD>b<EFBFBD>N:<3A>U<EFBFBD>E<EFBFBD>M<EFBFBD><4D><EFBFBD>U<EFBFBD><55><EFBFBD><EFBFBD><EFBFBD>O <20><><EFBFBD>{<7B>Z<EFBFBD>b<EFBFBD>g2015 <20>u<EFBFBD>[<5B>X<EFBFBD>^<5E>[<5B>p<EFBFBD>b<EFBFBD>N <20><><EFBFBD>{<7B><><EFBFBD><EFBFBD> BOX', '<EFBFBD>E<EFBFBD>B<EFBFBD>U<EFBFBD>[<5B>Y<EFBFBD>E<EFBFBD>I<EFBFBD>u<EFBFBD>E<EFBFBD>U<EFBFBD>E<EFBFBD>R<EFBFBD>[<5B>X<EFBFBD>g', 'K0008', '2014-4-28', 10952, 6000);
|
||||||
|
|
||||||
|
----------------------------------------
|
||||||
|
----------------------------------------
|
||||||
|
|
||||||
|
--<EFBFBD>q<EFBFBD>Ƀ}<EFBFBD>X<EFBFBD>^
|
||||||
|
CREATE TABLE store_m (
|
||||||
|
store_id CHAR(5) NOT NULL COMMENT '<EFBFBD>q<EFBFBD><EFBFBD>ID',
|
||||||
|
store_nm VARCHAR(50) NOT NULL COMMENT '<EFBFBD>q<EFBFBD>ɖ<EFBFBD>',
|
||||||
|
store_post_no CHAR(8) NOT NULL COMMENT '<EFBFBD>X<EFBFBD>֔ԍ<EFBFBD>',
|
||||||
|
store_prefecture_nm VARCHAR(4) NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||||
|
store_municipality_nm VARCHAR(50) NOT NULL COMMENT '<EFBFBD>s<EFBFBD>撬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||||
|
store_city_nm VARCHAR(50) NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>於',
|
||||||
|
store_address VARCHAR(50) NOT NULL COMMENT '<EFBFBD>Z<EFBFBD><EFBFBD>',
|
||||||
|
store_building_nm VARCHAR(50) COMMENT '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||||
|
PRIMARY KEY (store_id)
|
||||||
|
)
|
||||||
|
COMMENT '<EFBFBD>q<EFBFBD>Ƀ}<7D>X<EFBFBD>^';
|
||||||
|
INSERT INTO store_m VALUE ('W0001', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>q<EFBFBD><EFBFBD>', '140-0014', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>s', '<EFBFBD>i<EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>', 'XXXXXXXXXXXXXXXX', 'XXXXXXXX');
|
||||||
|
|
||||||
|
----------------------------------------
|
||||||
|
----------------------------------------
|
||||||
|
|
||||||
|
--<EFBFBD>Ƀ}<EFBFBD>X<EFBFBD>^
|
||||||
|
CREATE TABLE stock_m (
|
||||||
|
store_id CHAR(5) NOT NULL COMMENT '<EFBFBD>q<EFBFBD><EFBFBD>ID',
|
||||||
|
goods_id CHAR(10) NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>iID',
|
||||||
|
arrival_date DATE NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>ɓ<EFBFBD>',
|
||||||
|
arrival_num INT NOT NULL DEFAULT 0 COMMENT '<EFBFBD><EFBFBD><EFBFBD>ɐ<EFBFBD>',
|
||||||
|
security_num INT NOT NULL DEFAULT 0 COMMENT '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||||
|
PRIMARY KEY (arrival_date),
|
||||||
|
FOREIGN KEY (store_id) REFERENCES store_m(store_id),
|
||||||
|
FOREIGN KEY (goods_id) REFERENCES goods_m(goods_id)
|
||||||
|
)
|
||||||
|
COMMENT '<EFBFBD>Ƀ}<7D>X<EFBFBD>^';
|
||||||
|
INSERT INTO stock_m VALUE ('W0001', 'ITM0000001', '2012-8-24', 2, 2);
|
||||||
|
INSERT INTO stock_m VALUE ('W0001', 'ITM0000001', '2012-12-25', 3, 3);
|
||||||
|
INSERT INTO stock_m VALUE ('W0001', 'ITM0000001', '2013-6-1', 2, 2);
|
||||||
|
INSERT INTO stock_m VALUE ('W0001', 'ITM0000001', '2013-11-20', 5, 4);
|
||||||
|
INSERT INTO stock_m VALUE ('W0001', 'ITM0000001', '2014-8-8', 7, 0);
|
||||||
|
INSERT INTO stock_m VALUE ('W0001', 'ITM0000002', '2014-3-4', 100, 100);
|
||||||
|
INSERT INTO stock_m VALUE ('W0001', 'ITM0000002', '2014-9-5', 50, 45);
|
||||||
|
INSERT INTO stock_m VALUE ('W0001', 'ITM0000002', '2014-9-10', 60, 0);
|
||||||
|
INSERT INTO stock_m VALUE ('W0001', 'ITM0000003', '2013-9-17', 5, 2);
|
||||||
|
INSERT INTO stock_m VALUE ('W0001', 'ITM0000004', '2010-3-3', 10, 10);
|
||||||
|
INSERT INTO stock_m VALUE ('W0001', 'ITM0000004', '2012-10-5', 3, 3);
|
||||||
|
INSERT INTO stock_m VALUE ('W0001', 'ITM0000004', '2013-9-10', 6, 5);
|
||||||
|
INSERT INTO stock_m VALUE ('W0001', 'ITM0000004', '2014-4-3', 2, 0);
|
||||||
|
INSERT INTO stock_m VALUE ('W0001', 'ITM0000005', '2014-4-28', 150, 150);
|
||||||
|
INSERT INTO stock_m VALUE ('W0001', 'ITM0000005', '2014-5-20', 100, 86);
|
||||||
|
|
||||||
|
----------------------------------------
|
||||||
|
----------------------------------------
|
||||||
|
|
||||||
|
--<EFBFBD><EFBFBD><EFBFBD>Ƀe<EFBFBD>[<EFBFBD>u<EFBFBD><EFBFBD>
|
||||||
|
CREATE TABLE ins_stock_m (
|
||||||
|
goods_id CHAR(10) NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>iID',
|
||||||
|
store_id CHAR(5) NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>ɐ<EFBFBD><EFBFBD>q<EFBFBD><EFBFBD>ID',
|
||||||
|
ins_stock_exp_date DATE NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>ɗ\<5C><><EFBFBD><EFBFBD>',
|
||||||
|
ins_stock_cmp_date DATE COMMENT '<EFBFBD><EFBFBD><EFBFBD>Ɋ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||||
|
ins_stock_exp_num INT NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>ɗ\<5C>萔',
|
||||||
|
ins_stock_num INT COMMENT '<EFBFBD><EFBFBD><EFBFBD>ɐ<EFBFBD>',
|
||||||
|
PRIMARY KEY (ins_stock_exp_date),
|
||||||
|
FOREIGN KEY (goods_id) REFERENCES goods_m(goods_id),
|
||||||
|
FOREIGN KEY (store_id) REFERENCES store_m(store_id)
|
||||||
|
)
|
||||||
|
COMMENT '<EFBFBD><EFBFBD><EFBFBD>Ƀe<EFBFBD>[<5B>u<EFBFBD><75>';
|
||||||
|
INSERT INTO ins_stock_m VALUE ('ITM0000004', 'W0001', '2010-3-3', '2010-3-3', 10, 10);
|
||||||
|
INSERT INTO ins_stock_m VALUE ('ITM0000001', 'W0001', '2012-8-24', '2012-8-24', 2, 2);
|
||||||
|
INSERT INTO ins_stock_m VALUE ('ITM0000004', 'W0001', '2012-10-5', '2012-10-5', 3, 3);
|
||||||
|
INSERT INTO ins_stock_m VALUE ('ITM0000001', 'W0001', '2012-12-25', '2012-12-25', 3, 3);
|
||||||
|
INSERT INTO ins_stock_m VALUE ('ITM0000001', 'W0001', '2013-6-1', '2013-6-1', 2, 2);
|
||||||
|
INSERT INTO ins_stock_m VALUE ('ITM0000004', 'W0001', '2013-9-10', '2013-9-10', 6, 6);
|
||||||
|
INSERT INTO ins_stock_m VALUE ('ITM0000003', 'W0001', '2013-9-17', '2013-9-17', 5, 5);
|
||||||
|
INSERT INTO ins_stock_m VALUE ('ITM0000001', 'W0001', '2013-11-20', '2013-11-20', 5, 5);
|
||||||
|
INSERT INTO ins_stock_m VALUE ('ITM0000002', 'W0001', '2014-3-4', '2014-3-4', 100, 100);
|
||||||
|
INSERT INTO ins_stock_m VALUE ('ITM0000004', 'W0001', '2014-4-3', '2014-4-3', 2, 2);
|
||||||
|
INSERT INTO ins_stock_m VALUE ('ITM0000005', 'W0001', '2014-4-28', '2014-4-28', 150, 150);
|
||||||
|
INSERT INTO ins_stock_m VALUE ('ITM0000005', 'W0001', '2014-5-20', '2014-5-20', 100, 100);
|
||||||
|
INSERT INTO ins_stock_m VALUE ('ITM0000001', 'W0001', '2014-8-8', '2014-8-8', 7, 7);
|
||||||
|
INSERT INTO ins_stock_m VALUE ('ITM0000002', 'W0001', '2014-9-5', '2014-9-5', 50, 50);
|
||||||
|
INSERT INTO ins_stock_m VALUE ('ITM0000002', 'W0001', '2014-9-10', '2014-9-10', 60, 60);
|
||||||
|
INSERT INTO ins_stock_m VALUE ('ITM0000001', 'W0001', '2014-12-3', NULL, 5, NULL);
|
||||||
|
INSERT INTO ins_stock_m VALUE ('ITM0000002', 'W0001', '2014-12-10', NULL, 200, NULL);
|
||||||
|
INSERT INTO ins_stock_m VALUE ('ITM0000003', 'W0001', '2014-12-12', NULL, 3, NULL);
|
||||||
|
INSERT INTO ins_stock_m VALUE ('ITM0000004', 'W0001', '2014-12-15', NULL, 10, NULL);
|
||||||
|
INSERT INTO ins_stock_m VALUE ('ITM0000005', 'W0001', '2014-12-25', NULL, 80, NULL);
|
||||||
|
|
||||||
|
----------------------------------------
|
||||||
|
----------------------------------------
|
||||||
|
|
||||||
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
CREATE TABLE order_t (
|
||||||
|
order_no INT NOT NULL AUTO_INCREMENT COMMENT '<EFBFBD>ԍ<EFBFBD>',
|
||||||
|
order_date DATE NOT NULL COMMENT '<EFBFBD><EFBFBD>',
|
||||||
|
user_id CHAR(10) NOT NULL COMMENT '<EFBFBD>ڋqID',
|
||||||
|
sts_cd CHAR(5) NOT NULL COMMENT '<EFBFBD>X<EFBFBD>e<EFBFBD>[<5B>^<5E>X',
|
||||||
|
pay_div_cd CHAR(5) NOT NULL COMMENT '<EFBFBD>x<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||||
|
deli_exp_date DATE COMMENT '<EFBFBD>o<EFBFBD>ח\<5C><><EFBFBD><EFBFBD>',
|
||||||
|
deli_date DATE COMMENT '<EFBFBD>o<EFBFBD>ד<EFBFBD>',
|
||||||
|
deli_company VARCHAR(50) NOT NULL COMMENT '<EFBFBD>z<EFBFBD><EFBFBD><EFBFBD>Ǝ<EFBFBD>',
|
||||||
|
tracing_no CHAR(11) NOT NULL COMMENT '<EFBFBD>ǐՔԍ<EFBFBD>',
|
||||||
|
arrive_exp_date DATE COMMENT '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\<5C><><EFBFBD><EFBFBD>',
|
||||||
|
cash_deli_comm_rate INT NOT NULL DEFAULT 0 COMMENT '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>萔<EFBFBD><EFBFBD>',
|
||||||
|
postage INT NOT NULL DEFAULT 1836 COMMENT '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||||
|
tax INT NOT NULL DEFAULT 0 COMMENT '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||||
|
PRIMARY KEY (order_no),
|
||||||
|
FOREIGN KEY (user_id) REFERENCES user_m(user_id),
|
||||||
|
FOREIGN KEY (sts_cd) REFERENCES order_sts_m(sts_cd),
|
||||||
|
FOREIGN KEY (pay_div_cd) REFERENCES pay_div_m(pay_div_cd)
|
||||||
|
)
|
||||||
|
COMMENT '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
|
||||||
|
INSERT INTO order_t VALUE (1, '2014-11-20', 'CU00000003', 'ST010', 'PY002', '2014-11-20', '2014-11-20', '<EFBFBD><EFBFBD><EFBFBD>}<7D>g', 'xxxxxxxxxxx', '2014-11-21', 0, 1836, 208501);
|
||||||
|
INSERT INTO order_t VALUE (2, '2014-11-25', 'CU00000001', 'ST010', 'PY001', '2014-11-25', '2014-11-25', '<EFBFBD><EFBFBD><EFBFBD>}<7D>g', 'xxxxxxxxxxx', '2014-11-26', 0, 1836, 94520);
|
||||||
|
INSERT INTO order_t VALUE (3, '2014-11-30', 'CU00000005', 'ST010', 'PY001', '2014-12-1', '2014-12-2', '<EFBFBD><EFBFBD><EFBFBD>}<7D>g', 'xxxxxxxxxxx', '2014-12-3', 0, 1836, 108562);
|
||||||
|
INSERT INTO order_t VALUE (4, '2014-12-2', 'CU00000004', 'ST010', 'PY004', '2014-12-2', '2014-12-2', '<EFBFBD><EFBFBD><EFBFBD>}<7D>g', 'xxxxxxxxxxx', '2014-12-3', 510, 1836, 103310);
|
||||||
|
|
||||||
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڍ<EFBFBD>
|
||||||
|
CREATE TABLE order_detail_t (
|
||||||
|
order_detail_no INT NOT NULL AUTO_INCREMENT COMMENT '<EFBFBD>ڍהԍ<EFBFBD>',
|
||||||
|
order_no INT NOT NULL COMMENT '<EFBFBD>ԍ<EFBFBD>',
|
||||||
|
goods_id CHAR(10) NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>iID',
|
||||||
|
goods_unit_price INT NOT NULL DEFAULT 0 COMMENT '<EFBFBD><EFBFBD><EFBFBD>i<EFBFBD>P<EFBFBD><EFBFBD>',
|
||||||
|
goods_num INT NOT NULL DEFAULT 0 COMMENT '<EFBFBD><EFBFBD>',
|
||||||
|
PRIMARY KEY (order_detail_no),
|
||||||
|
FOREIGN KEY (order_no) REFERENCES order_t(order_no),
|
||||||
|
FOREIGN KEY (goods_id) REFERENCES goods_m(goods_id)
|
||||||
|
)
|
||||||
|
COMMENT '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڍ<EFBFBD>';
|
||||||
|
INSERT INTO order_detail_t VALUE (1, 1, 'ITM0000002', 12915, 100);
|
||||||
|
INSERT INTO order_detail_t VALUE (2, 1, 'ITM0000005', 10952, 80);
|
||||||
|
INSERT INTO order_detail_t VALUE (3, 1, 'ITM0000003', 24500, 1);
|
||||||
|
INSERT INTO order_detail_t VALUE (4, 1, 'ITM0000004', 3712, 5);
|
||||||
|
INSERT INTO order_detail_t VALUE (5, 1, 'ITM0000001', 79110, 5);
|
||||||
|
INSERT INTO order_detail_t VALUE (6, 2, 'ITM0000001', 79110, 1);
|
||||||
|
INSERT INTO order_detail_t VALUE (7, 2, 'ITM0000002', 12915, 50);
|
||||||
|
INSERT INTO order_detail_t VALUE (8, 2, 'ITM0000004', 3712, 5);
|
||||||
|
INSERT INTO order_detail_t VALUE (9, 2, 'ITM0000005', 10952, 40);
|
||||||
|
INSERT INTO order_detail_t VALUE (10, 3, 'ITM0000001', 79110, 3);
|
||||||
|
INSERT INTO order_detail_t VALUE (11, 3, 'ITM0000003', 24500, 1);
|
||||||
|
INSERT INTO order_detail_t VALUE (12, 3, 'ITM0000005', 10952, 100);
|
||||||
|
INSERT INTO order_detail_t VALUE (13, 4, 'ITM0000001', 79110, 2);
|
||||||
|
INSERT INTO order_detail_t VALUE (14, 4, 'ITM0000002', 12915, 60);
|
||||||
|
INSERT INTO order_detail_t VALUE (15, 4, 'ITM0000004', 3712, 8);
|
||||||
|
INSERT INTO order_detail_t VALUE (16, 4, 'ITM0000005', 10952, 30);
|
||||||
|
|
||||||
32
Answers/Question1.txt
Normal file
32
Answers/Question1.txt
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
--Q1
|
||||||
|
CREATE TABLE book_table (
|
||||||
|
book_id INT COMMENT '書籍ID',
|
||||||
|
book_name VARCHAR(50) COMMENT '書籍名',
|
||||||
|
author_name VARCHAR(50) COMMENT '著者',
|
||||||
|
price INT COMMENT '価格',
|
||||||
|
sales_flag INT COMMENT '販売有無'
|
||||||
|
);
|
||||||
|
|
||||||
|
--Q2
|
||||||
|
INSERT INTO book_table VALUES (10001, 'TwoPeace', '三田英一郎', 420, 1);
|
||||||
|
INSERT INTO book_table VALUES (10002, '名探偵金田二', '青山ふみや', 460, 1);
|
||||||
|
INSERT INTO book_table VALUES (20001, '坊ちゃま', '冬目漱岩', 460, 1);
|
||||||
|
INSERT INTO book_table VALUES (30001, '西方見聞録', '不明', 1000, 1);
|
||||||
|
INSERT INTO book_table VALUES (40010, '吾輩は犬である', '冬目漱岩', 420, 1);
|
||||||
|
|
||||||
|
--Q3
|
||||||
|
SELECT book_name, author_name FROM book_table;
|
||||||
|
|
||||||
|
--Q4
|
||||||
|
UPDATE book_table SET author_name = 'マール=コー=ポロ', sales_flag = 0 WHERE book_id = 30001;
|
||||||
|
SELECT * FROM book_table;
|
||||||
|
|
||||||
|
--Q5
|
||||||
|
SELECT * FROM book_table WHERE sales_flag = 1;
|
||||||
|
|
||||||
|
--Q6
|
||||||
|
SELECT * FROM book_table WHERE author_name = '冬目漱岩' AND price = 420;
|
||||||
|
|
||||||
|
--Q7
|
||||||
|
DELETE FROM book_table WHERE book_id = 20001;
|
||||||
|
SELECT * FROM book_table;
|
||||||
55
Answers/Question2.txt
Normal file
55
Answers/Question2.txt
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
--Q1
|
||||||
|
CREATE TABLE item_category (
|
||||||
|
category_id INT AUTO_INCREMENT COMMENT 'カテゴリID',
|
||||||
|
category_name VARCHAR(256) NOT NULL COMMENT 'カテゴリ名',
|
||||||
|
PRIMARY KEY (category_id)
|
||||||
|
)
|
||||||
|
INSERT INTO item_category (category_name) VALUES ('家具');
|
||||||
|
INSERT INTO item_category (category_name) VALUES ('飲料');
|
||||||
|
INSERT INTO item_category (category_name) VALUES ('食品');
|
||||||
|
|
||||||
|
--Q2
|
||||||
|
CREATE TABLE items (
|
||||||
|
item_id INT AUTO_INCREMENT COMMENT 'アイテムID',
|
||||||
|
name VARCHAR(256) NOT NULL COMMENT 'アイテム名',
|
||||||
|
price INT NOT NULL COMMENT '価格',
|
||||||
|
category_id INT COMMENT 'カテゴリID',
|
||||||
|
PRIMARY KEY (item_id),
|
||||||
|
FOREIGN KEY (category_id) REFERENCES item_category(category_id)
|
||||||
|
)
|
||||||
|
INSERT INTO items (name, price, category_id) VALUES ('ローマのテーブル', 150000, 1);
|
||||||
|
INSERT INTO items (name, price, category_id) VALUES ('げーたるーど2000 500ml', 370, 2);
|
||||||
|
INSERT INTO items (name, price, category_id) VALUES ('原始肉', 2500, 3);
|
||||||
|
INSERT INTO items (name, price, category_id) VALUES ('魅惑の椅子', 100000, 1);
|
||||||
|
|
||||||
|
--Q3
|
||||||
|
SELECT items.category_id, items.item_id, items.name, items.price, item_category.category_name
|
||||||
|
FROM items INNER JOIN item_category ON items.category_id = item_category.category_id;
|
||||||
|
|
||||||
|
--Q4
|
||||||
|
SELECT items.category_id, items.item_id, items.name, items.price, item_category.category_name
|
||||||
|
FROM items INNER JOIN item_category ON items.category_id = item_category.category_id
|
||||||
|
ORDER BY price ASC;
|
||||||
|
|
||||||
|
--Q5
|
||||||
|
SELECT items.category_id, items.item_id, items.name, items.price, item_category.category_name
|
||||||
|
FROM items INNER JOIN item_category ON items.category_id = item_category.category_id
|
||||||
|
WHERE category_name = '家具';
|
||||||
|
|
||||||
|
--Q6
|
||||||
|
SELECT items.category_id, items.item_id, items.name, items.price, item_category.category_name
|
||||||
|
FROM items INNER JOIN item_category ON items.category_id = item_category.category_id
|
||||||
|
WHERE price BETWEEN 1000 AND 50000;
|
||||||
|
|
||||||
|
--Q7
|
||||||
|
SELECT COUNT(item_id) AS data_count FROM items;
|
||||||
|
|
||||||
|
--Q8
|
||||||
|
SELECT items.category_id, items.item_id, items.name, items.price, item_category.category_name
|
||||||
|
FROM items INNER JOIN item_category ON items.category_id = item_category.category_id
|
||||||
|
WHERE items.price >= ALL (SELECT items.price FROM items);
|
||||||
|
|
||||||
|
--Q9
|
||||||
|
SELECT items.category_id, items.item_id, items.name, items.price, item_category.category_name
|
||||||
|
FROM items INNER JOIN item_category ON items.category_id = item_category.category_id
|
||||||
|
WHERE items.name LIKE '%の%';
|
||||||
90
Answers/Question2alpha.txt
Normal file
90
Answers/Question2alpha.txt
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
--Q1
|
||||||
|
SELECT items.item_id AS '商品ID',
|
||||||
|
items.name AS '商品名',
|
||||||
|
items.price AS '価格',
|
||||||
|
item_category.name AS 'カテゴリ名'
|
||||||
|
FROM items INNER JOIN item_category ON items.category_id = item_category.category_id
|
||||||
|
ORDER BY items.item_id ASC;
|
||||||
|
|
||||||
|
--Q2
|
||||||
|
SELECT orders.order_id AS '注文ID',
|
||||||
|
orders.order_time AS '注文日時',
|
||||||
|
users.name AS 'ユーザ名',
|
||||||
|
items.name AS '商品名',
|
||||||
|
items.price AS '価格',
|
||||||
|
order_items.quantity AS '数量'
|
||||||
|
FROM orders
|
||||||
|
INNER JOIN order_items ON orders.order_id = order_items.order_id
|
||||||
|
INNER JOIN users ON orders.user_id = users.user_id
|
||||||
|
INNER JOIN items ON order_items.item_id = items.item_id
|
||||||
|
ORDER BY orders.order_id ASC;
|
||||||
|
|
||||||
|
--Q3
|
||||||
|
SELECT orders.order_id AS '注文ID',
|
||||||
|
orders.order_time AS '注文日時',
|
||||||
|
users.name AS 'ユーザ名',
|
||||||
|
SUM(items.price*order_items.quantity) AS '合計額'
|
||||||
|
FROM orders
|
||||||
|
INNER JOIN order_items ON orders.order_id = order_items.order_id
|
||||||
|
INNER JOIN users ON orders.user_id = users.user_id
|
||||||
|
INNER JOIN items ON order_items.item_id = items.item_id
|
||||||
|
GROUP BY orders.order_id
|
||||||
|
ORDER BY orders.order_id ASC;
|
||||||
|
|
||||||
|
--Q4
|
||||||
|
SELECT SUBSTRING(orders.order_time, 1, 7) AS '注文月',
|
||||||
|
SUM(order_items.quantity) AS '注文数'
|
||||||
|
FROM orders
|
||||||
|
INNER JOIN order_items ON orders.order_id = order_items.order_id
|
||||||
|
GROUP BY SUBSTRING(orders.order_time, 1, 7);
|
||||||
|
|
||||||
|
--Q5
|
||||||
|
SELECT SUBSTRING(orders.order_time, 1, 4) AS '注文年',
|
||||||
|
SUM(order_items.quantity*items.price) AS '売上額'
|
||||||
|
FROM orders
|
||||||
|
INNER JOIN order_items ON orders.order_id = order_items.order_id
|
||||||
|
INNER JOIN items ON order_items.item_id = items.item_id
|
||||||
|
GROUP BY SUBSTRING(orders.order_time, 1, 4)
|
||||||
|
ORDER BY SUBSTRING(orders.order_time, 1, 4) ASC;
|
||||||
|
|
||||||
|
--Q6
|
||||||
|
SELECT SUM(order_items.quantity*items.price) AS '売上額'
|
||||||
|
FROM order_items INNER JOIN items ON order_items.item_id = items.item_id;
|
||||||
|
|
||||||
|
--Q7
|
||||||
|
SELECT item_category.name AS 'カテゴリ名',
|
||||||
|
SUM(order_items.quantity*items.price) AS '売上額'
|
||||||
|
FROM order_items
|
||||||
|
INNER JOIN items ON items.item_id = order_items.item_id
|
||||||
|
INNER JOIN item_category ON item_category.category_id = items.category_id
|
||||||
|
GROUP BY item_category.category_id
|
||||||
|
ORDER BY 売上額 DESC;
|
||||||
|
|
||||||
|
--Q8
|
||||||
|
SELECT items.name AS '商品名',
|
||||||
|
SUM(order_items.quantity*items.price) AS '売上額'
|
||||||
|
FROM order_items
|
||||||
|
INNER JOIN items ON items.item_id = order_items.item_id
|
||||||
|
GROUP BY items.name
|
||||||
|
ORDER BY 売上額 DESC;
|
||||||
|
|
||||||
|
--Q9
|
||||||
|
SELECT item_category.name AS 'カテゴリ名',
|
||||||
|
SUM( 100*order_items.quantity*items.price/
|
||||||
|
(SELECT SUM(order_items.quantity*items.price)
|
||||||
|
FROM order_items INNER JOIN items ON order_items.item_id = items.item_id) ) AS '構成比(%)'
|
||||||
|
FROM order_items
|
||||||
|
INNER JOIN items ON items.item_id = order_items.item_id
|
||||||
|
INNER JOIN item_category ON item_category.category_id = items.category_id
|
||||||
|
GROUP BY item_category.category_id
|
||||||
|
ORDER BY 構成比(%) DESC;
|
||||||
|
|
||||||
|
--Q10
|
||||||
|
SELECT items.name AS '商品名',
|
||||||
|
SUM( 100*order_items.quantity*items.price/
|
||||||
|
(SELECT SUM(order_items.quantity*items.price)
|
||||||
|
FROM order_items INNER JOIN items ON order_items.item_id = items.item_id) ) AS '構成比(%)'
|
||||||
|
FROM order_items
|
||||||
|
INNER JOIN items ON items.item_id = order_items.item_id
|
||||||
|
GROUP BY items.name
|
||||||
|
ORDER BY 構成比(%) DESC;
|
||||||
Reference in New Issue
Block a user