-- John Aromando -- SQL Alias's --

use ogcPubLev1 --use database

select lname, sales.repid, count(ordnum), sum(qty) --no field names
from sales inner join Slspers
on Slspers.repid = Sales.repid
group by lname, sales.repid --lname first, sales.repid second
order by count(ordnum), sum(qty) --count(ordnum) first, sum(qty) second

select lname, sales.repid, count(ordnum) as Count_Orders, sum(qty) as Sum_Qty --now field names
from sales inner join Slspers
on Slspers.repid = Sales.repid
group by lname, sales.repid
order by count(ordnum) desc, sum(qty) desc

select lname, s.repid, count(ordnum) as Count_Orders, sum(qty) as Sum_Qty
from sales as s inner join Slspers as r
on r.repid = s.repid
group by lname, s.repid
order by count(ordnum) desc, sum(qty) desc

select State, count(custnum) as "Count of West Coast Customers" --if ever wanting to use spaces
from Customers
where state = 'CA' or state = 'WA'
group by state
order by count(custnum) asc




