Query 1
Query 1
select SNAME from Salespeople where SNUM in(select SNUM from Orders)
--6List names of all customers matched with the salespeople serving them.
select CNAME from Customers where SNUM in(select SNUM from Salespeople)
--7Count the orders of each of the salespeople and output the results in
descending order
where s.CITY=c.CITY
--9Find all the customers in SanJose who have a rating above 200.
select * from Customers where RATING>200 and CITY='SanJose'
--11.List all the orders of Salesperson Motika from the orders table
select ONUM from orders where SNUM=(select SNUM from salespeople where
SNAME='Motika')
select * from Customers where SNUM in(select SNUM from Orders where
ODATE='03/10/90')
--13.Give the sums of the amounts from the Orders table, grouped by date,
--eliminating all those dates where the SUM was not at least 2000 above the
maximum Amount.
--14 Select all orders that had amounts that were greater than at least one of the
orders from
--October 6..
select * from Orders where AMT>any(select AMT from Orders where ODATE='06/10/90')
--15 List all the largest orders for October 3, for each salesperson.
--16 Find all customers located in cities where Serres has customers.
--19 Find salespeople whose name starts with P and fourth character is I
--20.Write a query that uses a subquery to obtain all orders for the customer
named Cisneros.Assume you do not know his customer number
select ONUM from Orders where SNUM=(select SNUM from Customers where
CNAME='Cisneros')
--22.Sort the salespeople table in the following order : snum, sname, commission,
city.
--23 Select all customers whose names fall in between A and G alphabetical
range
select CNAME from Customers where CNAME between 'A' and 'G'order by CNAME asc
--24 Write a query that totals the orders for each day and places the results in
descending order.
--or
select sum(amt) as amt,odate from orders group by odate order by sum(amt) desc;
--25Write a select command that produces the rating followed by the name of each
customer in SanJose.
--26 Find all orders with above average amounts for their customers.
select onum,AMT from orders where amt >(select avg(amt) from orders)
--29.Write a query that joins the customer table to itself to find all pairs or
customers served by a single salesperson.
and c.cname!=c2.cname;
--30.Write a query that will give you all orders for more than $1000.00
--31.Write a query that lists each order number followed by the name of customer
who made that order.
--32.Write two queries that will produce all orders taken on October 3 or October
4.
--33.Find all rows from the customers table for which the sales person number is
1001.
--35.Find all sales people for whom there are customers that follow them in
alphabetical order.
--36.Write a query that produces the names and ratings of all customers who have
average orders..
--37. Find the sum of all Amounts from the orders table.
--38. Write a query that gives the names of both the salesperson and the customer
for each order after the order number.
--41. Find all salespeople who have customers with more than one current order.
select distinct snum from orders where cnum in (select cnum from orders group by
cnum having count(cnum)>1)
--43.Find all orders credited to the same salesperson who services Hoffman. (cnum
2001).
select onum from orders where snum in(select snum from customers where
cname='Hoffman')
--or
--44.Find all salespeople whose commission is in between 0.10 and 0.12 (both
inclusive).
--or
--45.Write a query that will give you the names and cities of all salespeople in
London with acommission above 0.10.
--47.Write a query that selects the first customer in alphabetical order whose
name begins withG.
--48.Write a query that counts the number of different non NULL city values in the
customerstable.
--50. Find all customers who are not located in SanJose and whose rating is above
200.
--51. Give a simpler way to write this query.SELECT snum, sname, city, comm. FROM
salespeopleWHERE (comm.>+0.12 OR comm.<0.14);
--or
select onum,odate from orders where cnum in(select cnum from customers where
cname='Hoffman')