You are on page 1of 4

select * from orders inner join customers on orders.customer_id =customers.

id ->tabloları birbiri ile


bağla hangi tablo hangi sütun bağlı olan bütün tablo gelir

select orders.id,customers.first_name,orders.order_date from orders inner join customers on


orders.customer_id =customers.id ->tabloları birbiri ile bağla hangi tablo hangi sütun hangi veriler

select orders.id,CONCAT(customers.first_name,customers.last_name) as isim_soyisim,


orders.order_date from orders inner join customers on orders.customer_id =customers.id

isim soyisim birleştirdik

select orders.id,CONCAT(customers.first_name,customers.last_name) as isim_soyisim,


orders.order_date from orders inner join customers on orders.customer_id =customers.id where
customers.city='Denver' -> şehir Denver olan kullanıcılar

select c.first_name,o.id as orderid from customers c

left join orders o

on o.customer_id =c.id hangi tablolari bağladık

where o.id is null sipariş vermemiş kullanıcıları göster

order by c.first_name hangi bilgiyi göstersin

soldaki verilerin hepsi olacak ama sağdaki verilerin hepsi olmak zorunda değil

select o.id,e.first_name from orders o right join employees e

on e.id =o.employee_id hangi tablolar bağlandı

where o.id is null hangi değeri arıyorsunuz

order by o.id

sağdaki verilerin hepsi olacak ama soldaki verilerin hepsi olmak zorunda değil

verileri farklı tabloya aktarma

insert into employee_performans(employee_id,fullname,email,satis_adeti)

select e.id,concat(e.first_name,'',e.last_name) as fullname,e.email_address,count(o.id) as adet from


employees e left join orders o on e.id=o.employee_id group by e.id

bilgiler hangi tablodan alınacak aktarılacak tablo adı hangi bilgiler aktarılacak
Başka tablodan Başka tabloyu güncelleme

update employees e inner join employee_performans ep

on e.id=ep.employee_id ->neleri ilişkilendirdik

set e.email_address=ep.email ->neyi güncelleyeceğiz

where ep.email like '%update%' ->Neye göre güncelleyeceğiz

delete customers

from customers left join orders

on orders.customer_id=customers.id

where orders.customer_id is null and customers.id=13 customer_id si 13 ve spariş_id si null olan


değeri db den sildik

select email from employee_performans

union all ->iki tablodaki verileri sadece 1 defa getirir bütün veriler için ekleriz

select email_address from employees

bu örnekte email adreslerini getirdik

ALT SORGULAR

select id,order_date from orders where status_id=3

tamamlanan siparişlerin tarih ve idlerini verir

select id,order_date from orders where status_id=(select id from orders_status where


status_name='Closed')

siparişin statü name i closed olan gönderi numaraları gelir

select c.id,c.first_name,c.last_name,(select count(o.id) from orders o where o.customer_id=c.id) as


ordercount from customers c

hangi müşteri kaç sipariş verdi


hangi üründen kaç tane satılmış

-- select p.id,p.product_name,count(*) adet from products p inner join order_details od on


p.id=od.product_id group by p.id

en çok kazandıran 3 ürün

-- select p.id,p.product_name,sum(od.quantity*od.unit_price) as Kazanç from products p inner join


order_details od on p.id=od.product_id group by p.id order by kazanç desc limit 3

Hangi kargo şirketlerine toplam ne kadar ödeme yapılmış

-- select s.company,sum(o.shipping_fee) as total from orders o inner join shippers s on


s.id=o.shipper_id group by s.id order by total

-- En uygun kargo şirketi hangisidir

-- select s.company,avg(o.shipping_fee) as ortalama from orders o inner join shippers s on s.id=


o.shipper_id where o.shipping_fee >0 group by s.id having count(o.id ) > 10 10'dan fazla kargo
taşıyan firmalar için hesaplıyoruz

select id,product_name from products where id in (select product_id from order_details where
quantity>100) ->100 den fazla spariş edilen ürünleri göster

select id,first_name from customers c where EXISTS(select id from orders o where c.id=
o.customer_id and payment_type= 'Credit Card') -> doğru olan değerleri yazdırıyor

select id,first_name,last_name from customers c where EXISTS(select count(*) from orders where
c.id=orders.customer_id group by orders.customer_id having count(*)>2)

select id,product_name,list_price from products where id =any (select product_id from order_details
where quantity>10) 10 dan fazla miktarı olan ürünleri göster *or* or*

select id,product_name,list_price from products where id >all (select product_id from order_details
where quantity>10) id si adet idsinden büyük olan ürünleri göster

select * from customers2 where salary>any(select avg(salary) from customers2) maaşı ortalamanın
üzerinde olan kullanıcılar gelir

You might also like