Commit 978f6c8a authored by 三階松隼人's avatar 三階松隼人
Browse files

SQL演習課題

parent 074653d7
select * from M_PRODUCT;
\ No newline at end of file
--select * from M_PRODUCT;
select * from M_PRODUCT where (5000 <= price) and (price <= 10000);
\ No newline at end of file
--select * from M_PRODUCT;
select * from M_PRODUCT where proname like 'T%' ;
\ No newline at end of file
--select * from M_PRODUCT;
select * from M_PRODUCT where proname like '%T%' ;
\ No newline at end of file
--select * from M_PRODUCT;
select * from M_PRODUCT where (len(proname) >= 8) and (enable = 'True');
\ No newline at end of file
--select *, (price - cost) as sagaku from M_PRODUCT;
select proname, price, cost from M_PRODUCT where price - cost >= 1000;
--select * from M_PRODUCT;
select * from M_PRODUCT where enable = 'true' order by price;
\ No newline at end of file
--select * from M_PRODUCT;
select * from M_PRODUCT where enable = 'true' order by cost desc;
\ No newline at end of file
--select * from M_PRODUCT;
select * from M_PRODUCT where enable = 'true' order by price desc, cost asc;
\ No newline at end of file
select * from M_PRODUCT;
select distinct price from M_PRODUCT order by price asc;
\ No newline at end of file
--select * from M_PRODUCT;
select avg(price) as avg_price from M_PRODUCT;
\ No newline at end of file
select * from M_CUSTOMER;
\ No newline at end of file
--select * from M_PRODUCT;
select max(cost) as max_cost, min(cost) as min_cost from M_PRODUCT;
\ No newline at end of file
--select * from M_CUSTOMER;
select count(address) as cnt_country_excluding_Japan from M_CUSTOMER where address != '日本'; --Nullを除外した場合
select count(*) as cnt_country_excluding_Japan from M_CUSTOMER where (address != '日本') or (address is null); --Nullを除外した場合
\ No newline at end of file
--select * from M_PRODUCT;
--select left(proname,5), price from M_PRODUCT where left(proname,5) like '%O%';
select sum(price) sum_price from M_PRODUCT where left(proname,5) like '%O%';
\ No newline at end of file
--gp
--select * from M_CUSTOMER order by empcode asc;
--select * from M_EMPLOYEE order by empcode asc;
select * from M_CUSTOMER inner join M_EMPLOYEE on M_CUSTOMER.empcode = M_EMPLOYEE.empcode order by M_EMPLOYEE.empcode asc;
--SOgp
--select * from M_CUSTOMER order by empcode asc;
--select * from M_EMPLOYEE order by empcode asc;
select * from M_CUSTOMER full join M_EMPLOYEE on M_CUSTOMER.empcode = M_EMPLOYEE.empcode order by M_CUSTOMER.empcode asc;
--内部結合を使用
--select * from M_CUSTOMER order by empcode asc;
--select * from M_EMPLOYEE order by empcode asc;
--select * from T_SALE;
/*
M_CUSTOMERとM_EMPLOYEEには、empcodeが共通
M_CUSTOMERとT_SALEには、cuscodeが共通
M_EMPLOYEEとT_SALEには、共通する列名がない
*/
select * from M_CUSTOMER inner join M_EMPLOYEE on M_CUSTOMER.empcode = M_EMPLOYEE.empcode inner join T_SALE on M_CUSTOMER.cuscode = T_SALE.cuscode;
--内部結合を使用
--select * from M_PRODUCT;
--select * from T_SALE where saledate >= ;
/*
M_PRODUCTとT_SALEには、procodeが共通
*/
select * from T_SALE inner join M_PRODUCT on T_SALE.procode = M_PRODUCT.procode where year(T_SALE.SALEDATE) = 2010 order by T_SALE.procode asc;
--左外部結合
/*
T_SALE内にprice(値段)のデータがないから外部から参照する必要あり
M_PRODUCTにpriceあり、procodeが共通
M_PRODUCT内の情報はpriceだけでよくないか?
*/
--select * from T_SALE order by saledate asc;
--select * from M_PRODUCT;
--select * from T_SALE where year(saledate) = 2009 order by saledate asc; --2009年のT_SALE
--select * from T_SALE left join M_PRODUCT on T_SALE.procode = M_PRODUCT.procode where (year(saledate) = 2009) and (M_PRODUCT.price >= 10000) order by saledate asc; --2009年のT_SALEとM_PRODUCT(全体)を左外部結合
select T_SALE.saleid, T_SALE.cuscode, T_SALE.procode, T_SALE.number, M_PRODUCT.price, T_SALE.saledate from T_SALE left join M_PRODUCT on T_SALE.procode = M_PRODUCT.procode where (year(saledate) = 2009) and (M_PRODUCT.price >= 10000) order by saledate asc;--2009年のT_SALEにM_PRODUCTのpriceのみを結合
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment