Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
20 views

SQL

Uploaded by

gokul nath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

SQL

Uploaded by

gokul nath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

SQL

Sales :

order_id
product_id
order_date
total_amount
sales_person_id
---------------------------------
Products :

product_id
product_name
product_category
---------------------------------
Sales_Person :

person_id
manager_id
assigned_region
---------------------------------

1. find total no of products sold for each category

select
product_category, count(product_id) as count_products
from
products p
inner join
sales s on p.product_id = s.product_id
group by
product_category

2. asked to show also the products not sold - changed inner to left join

3. then asked to convert null values in count_products to zero

(Coalesce function)
4. (case)
--------------------------------

total sales for the past six days

with six_days as(


select
dense_rank() over(order by order_date desc)
from
sales
where order_date <=6
)

select
sum(total_amount)
from
six_days
(date_functions) to get
--------------------------------------------------------

union vs union all


groupby vs having

You might also like