Professional Documents
Culture Documents
SQL
SQL
order_id)
num_ordenes from customers cm
join orders od on cm.customer_id = od.customer_id
join employees ee on cm.account_mgr_id = ee.employee_id
join departments dp on ee.department_id = dp.department_id
join locations lc on dp.location_id = lc.location_id
join countries ct on lc.country_id = ct.country_id
where ct.country_id = 'UK' and od.order_date >= to_date('01/01/2000','DD/MM/YYYY')
group by cm.cust_first_name ||' '|| cm.cust_last_name
select pi.product_id,oo.order_date,count(oo.order_id),count(oi.product_id),
case
when count(oo.order_id)> count(oi.product_id) then 'descuento'
when count(oo.order_id)< count(oi.product_id) then 'recargo'
else 'igual'
end as verificacion
from product_information pi
join order_items oi on pi.product_id = oi.product_id
join orders oo on oi.order_id = oo.order_id
join employees ee on oo.sales_rep_id = ee.employee_id
join departments dd on ee.department_id = dd.department_id
join locations lc on dd.location_id = lc.location_id
join countries cc on lc.country_id = cc.country_id
where cc.country_id = 'UK' and oo.order_date >= date '2007-01-01' and oo.order_date
<= date '2007-12-31'
group by pi.product_id,oo.order_date;