Handson 8
Handson 8
use javatraining;
# Question no-1
# create worldcity table
#1. For all the different countries contained in the WORLDCITY table, display their
names and the continent in which they are located.
# Make sure that no country name is duplicated.
select distinct country,continent from worldcity;
#2. Write an SQL query to display the list of the city and country for all the
cities that begin with letter R.
select city, country from worldcity where city like 'R%';
#3. Write an SQL query to display the list of the city and country for all the
cities that end with letter A.
select city,country from worldcity where city like '%A';
#4. Write an SQL query to display the list of the city and country for all the
cities that begin with letter M and
# have exactly six letters in them.
select city,country from worldcity where city like '%M_____';
#5. Write an SQL query to display the list of the city and country for all the
cities that contain an A as the second letter.
select city,country from worldcity where city like '_A%';
# Question no-2
# create customer table
#2. Display the details of all customers who purchased from the supplier 2.
SELECT c.* FROM CUSTOMER c JOIN ORDERS o ON c.CUSTID = o.CUSTID JOIN ITEMS i ON
o.ITEMID = i.ITEMID WHERE i.SUPPLIERID = 2;
#3. Display CUSTID, FNAME, LNAME of all customers whose purchase date is after
January 2005.
SELECT CUSTID, FNAME, LNAME FROM CUSTOMER WHERE DATEFIRSTPURCHASED > '2005-01-01';
#4. Display the details of all suppliers who are from location Coimbatore.
SELECT * FROM SUPPLIER WHERE SCITY = 'Coimbatore';
#5. Display the details of all suppliers whose name stars with G.
SELECT * FROM SUPPLIER WHERE SNAME LIKE 'G%';
#6. Display the details of all customers, who do not have the alphabet e in their
LNAME.
SELECT * FROM CUSTOMER WHERE LNAME NOT LIKE '%e%';
#7. Display the details of the entire customer whose first date of purchase is in
2006 and arrange it in descending order.
SELECT * FROM CUSTOMER WHERE DATEFIRSTPURCHASED >= '2006-01-01' ORDER BY
DATEFIRSTPURCHASED DESC;
#8. Display the details of all the orders where the quantity is less than 35.
SELECT * FROM ORDERS WHERE QUANTITY < 35;
#10. Display the details of all items where SUPPLIERID is 3 and the MINQTY is
greater than 7 order by ITEMID.
SELECT * FROM ITEMS WHERE SUPPLIERID = 3 AND MINQTY > 7 ORDER BY ITEMID;
create database javatraining;
use javatraining;
# Question no-1
#1. For all the different countries contained in the WORLDCITY table, display their
names and the continent in which they are located.
# Make sure that no country name is duplicated.
select distinct country,continent from worldcity;
#2. Write an SQL query to display the list of the city and country for all the
cities that begin with letter R.
select city, country from worldcity where city like 'R%';
#3. Write an SQL query to display the list of the city and country for all the
cities that end with letter A.
select city,country from worldcity where city like '%A';
#4. Write an SQL query to display the list of the city and country for all the
cities that begin with letter M and
# have exactly six letters in them.
select city,country from worldcity where city like '%M_____';
#5. Write an SQL query to display the list of the city and country for all the
cities that contain an A as the second letter.
select city,country from worldcity where city like '_A%';
# Question no-2
# create customer table
create table customer (
custid int primary key,
fname varchar(30),
lname varchar(30),
address varchar(50),
phoneno varchar(15) not null,
city varchar(20),
country varchar(20),
datefirstpurchased date,
supplierid int,
foreign key (`supplierid`) references supplier(`supplierid`)
);
#2. Display the details of all customers who purchased from the supplier 2.
SELECT c.* FROM CUSTOMER c JOIN ORDERS o ON c.CUSTID = o.CUSTID JOIN ITEMS i ON
o.ITEMID = i.ITEMID WHERE i.SUPPLIERID = 2;
#3. Display CUSTID, FNAME, LNAME of all customers whose purchase date is after
January 2005.
SELECT CUSTID, FNAME, LNAME FROM CUSTOMER WHERE DATEFIRSTPURCHASED > '2005-01-01';
#4. Display the details of all suppliers who are from location Coimbatore.
SELECT * FROM SUPPLIER WHERE SCITY = 'Coimbatore';
#5. Display the details of all suppliers whose name stars with G.
SELECT * FROM SUPPLIER WHERE SNAME LIKE 'G%';
#6. Display the details of all customers, who do not have the alphabet e in their
LNAME.
SELECT * FROM CUSTOMER WHERE LNAME NOT LIKE '%e%';
#7. Display the details of the entire customer whose first date of purchase is in
2006 and arrange it in descending order.
SELECT * FROM CUSTOMER WHERE DATEFIRSTPURCHASED >= '2006-01-01' ORDER BY
DATEFIRSTPURCHASED DESC;
#8. Display the details of all the orders where the quantity is less than 35.
SELECT * FROM ORDERS WHERE QUANTITY < 35;
#10. Display the details of all items where SUPPLIERID is 3 and the MINQTY is
greater than 7 order by ITEMID.
SELECT * FROM ITEMS WHERE SUPPLIERID = 3 AND MINQTY > 7 ORDER BY ITEMID;