use kiinDB;
select name as ๊ณ ๊ฐ๋ช ,
passwd as ๋น๋ฐ๋ฒํธ,
email as ์ด๋ฉ์ผ,
number as ์ฐ๋ฝ์ฒ,
address as ์ฃผ์,
profile_img as ํ๋กํ์ฌ์ง,
concat(membership, 'ํ์') as ๋ฉค๋ฒ์ญ
fromuser u
innerjoin (select membership, user_id from membership) m on u.id = m.user_id
innerjoin (select address, user_id, min(id) from address) a on u.id = a.user_id
where u.id =1
- ์ฃผ๋ฌธ๋ชฉ๋ก
use kiinDB;
select o.created_at as ์ฃผ๋ฌธ์ผ์,
o.updated_at,
shipment as ๋ฐฐ์ก์ข ๋ฅ,
shipment_img_url as ๋ฐฐ์ก์ด๋ฏธ์ง,
concat(name, space(1), o2.option) as ์ํ์ด๋ฆ,
price as ๊ฐ๊ฒฉ,
stock as ์ฃผ๋ฌธ๊ฐ์,
prod_img as ์ํ์ด๋ฏธ์ง,
(casewhen
o.status ='Y'then'๋ฐฐ์ก์๋ฃ'else'๋ฐฐ์ก ์ค'end) as ๋ฐฐ์ก์ํ,
(casewhen
o.status ='Y'and datediff(o.updated_at,current_timestamp) <1then concat('์ด์ ',space(1),date_format(o.updated_at,'%m/%d/%W'),space(1),'๋์ฐฉ')
when
o.status ='Y'and datediff(o.updated_at,current_timestamp) >1then concat(date_format(o.updated_at,'%m/%d/%W'),'๋์ฐฉ')
when o.status='N'and date_format(o.created_at,'%h') <12then'์ค๋ ์คํ ๋์ฐฉ ๋ณด์ฅ'else concat(date_format(DATE_ADD(o.created_at, INTERVAL1DAY),'%m/%d/%W'),'๋์ฐฉ๋ณด์ฅ')
end) as ๋ฐฐ์ก์ํ
from order_ o
innerjoin shipments_mapping sm on o.prod_id = sm.prod_id
innerjoin shipments s on sm.shipment_id = s.id
innerjoin product p on o.prod_id = p.id
innerjoin option_mapping om on p.id = om.prod_id
innerjoin option_ o2 on om.option_id = o2.id
where o.buyer_id =1and o2.id =1;
-์ฃผ๋ฌธ์์ธ
use kiinDB;
select user.name as ์ด๋ฆ,
payment as ๊ฒฐ์ ์๋จ,
number as ํธ๋ํฐ๋ฒํธ,
address as ์ฃผ์,
o.created_at as ๊ตฌ์ ์ผ์,
o.id as ์ฃผ๋ฌธ๋ฒํธ,
shipment as ๋ฐฐ์ก์ข ๋ฅ,
shipment_img_url as ๋ฐฐ์ก์ด๋ฏธ์ง,
(casewhen s.id ='1'then'0์'when s.id ='2'then'0์'else'3000์'end) as ๋ฐฐ์ก๋น,
concat(p.name, space(1), o2.option) as ์ํ์ด๋ฆ,
price as ๊ฐ๊ฒฉ,
stock as ์ฃผ๋ฌธ๊ฐ์,
prod_img as ์ํ์ด๋ฏธ์ง,
(casewhen
o.status ='Y'then'๋ฐฐ์ก์๋ฃ'else'๋ฐฐ์ก ์ค'end) as ๋ฐฐ์ก์ํ,
(casewhen
o.status ='Y'and datediff(o.updated_at, current_timestamp) <1then concat('์ด์ ', space(1), date_format(o.updated_at, '%m/%d/%W'), space(1), '๋์ฐฉ')
when
o.status ='Y'and datediff(o.updated_at, current_timestamp) >1then concat(date_format(o.updated_at, '%m/%d/%W'), '๋์ฐฉ')
when o.status ='N'and date_format(o.created_at, '%h') <12then'์ค๋ ์คํ ๋์ฐฉ ๋ณด์ฅ'else concat(date_format(DATE_ADD(o.created_at, INTERVAL1DAY), '%m/%d/%W'), '๋์ฐฉ๋ณด์ฅ')
end) as ๋ฐฐ์ก์ํ
from order_ o
innerjoin shipments_mapping sm on o.prod_id = sm.prod_id
innerjoin shipments s on sm.shipment_id = s.id
innerjoin product p on o.prod_id = p.id
innerjoin option_mapping om on p.id = om.prod_id
innerjoin (selectmin(id),'option',id from option_) o2 on om.option_id = o2.id
innerjoinuseron o.buyer_id = user.id
leftjoin (selectmin(id),address,user_id from address) a on user.id = a.user_id
innerjoin order_payment op on op.order_id = o.id
innerjoin payments_list pl on pl.id = op.payment_id
where o.id =5;
-์ต๊ทผ ๋ณธ ์ํ
use kiinDB;
select u.id,
p.prod_img,
p.name,
p.price AS ์๋๊ฐ๊ฒฉ,
round((p.price - p.price*(discount/100)),0) AS ํ ์ธ๊ฐ,
(casewhen p.status='Y'then'๊ตฌ๋งค๊ฐ๋ฅ'when p.status='N'then'ํ์ 'end) AS ํ์ ์ ๋ฌด,
shipment AS ๋ฐฐ์ก,
avgscore AS ํ๊ท ๋ณ์ ,
reviewCount AS ๋ฆฌ๋ทฐ๊ฐ์
fromuser u
innerjoin recently_viewed rv on u.id = rv.user_id
innerjoin product p on rv.prod_id = p.id
innerjoin shipments_mapping sm on p.id = sm.prod_id
innerjoin shipments s on sm.shipment_id = s.id
innerjoin (select prod_id, count(r.id) AS reviewCount, avg(score) AS avgscore
from review r
innerjoin score s2 on r.id = s2.review_id
groupby prod_id) r on p.id = r.prod_id
leftjoin (select discount,prod_id from discount_prod) dp on p.id = dp.prod_id
where u.id =1groupby p.id
limit 20
-์ํ ํ์ด์ง
use kiinDB;
select prod_img,price AS ์๋๊ฐ, round((p.price - p.price*(discount/100)),0) AS ํ ์ธ๊ฐ,name,brand,o.`option` AS ์ต์ ,avgScore AS ํ๊ท ๋ณ์ , ๋ฆฌ๋ทฐ์, shipment
from product p
innerjoin (selectcount(r.id) AS ๋ฆฌ๋ทฐ์, round(avg(score),0) AS avgScore,prod_id from review r innerjoin score s on r.id = s.review_id groupby prod_id) r on r.prod_id= p.id
innerjoin shipments_mapping sm on p.id = sm.prod_id
innerjoin shipments s2 on sm.shipment_id = s2.id
innerjoin brand b on p.brand_id = b.id
innerjoin option_mapping om on p.id = om.prod_id
innerjoin (selectmin(id) AS id,`option` from option_) o on om.option_id = o.id
innerjoin discount_prod dp on p.id = dp.prod_id
where p.id =1