0% found this document useful (0 votes)
96 views6 pages

SQL Insert Queries and Data Analysis

The document contains SQL queries to insert data into different tables like exporter, customer, manager, fish_details, import_cost, export_price, import_details, and export_details. It also contains 20 queries to retrieve data from these tables by joining them based on different conditions.

Uploaded by

love2390
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views6 pages

SQL Insert Queries and Data Analysis

The document contains SQL queries to insert data into different tables like exporter, customer, manager, fish_details, import_cost, export_price, import_details, and export_details. It also contains 20 queries to retrieve data from these tables by joining them based on different conditions.

Uploaded by

love2390
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

INSERT QUERIES

Exporter Table insert into exporter values(101,'Bob',2449686,4274112,'[email protected]'); insert into exporter values(102,'chris',2447872,4001234,'[email protected]'); insert into exporter values(103,'sam',2447321,4123456,'[email protected]'); insert into exporter values(104,'lui',2123456,4789241,'[email protected]'); insert into exporter values(105,'peter',2478962,4274113,'[email protected]'); Customer Table insert into customer values(201,'robert',2535313,2449613,'[email protected]'); insert into customer values(202,'mogambo',2545414,2449614,'[email protected]'); insert into customer values (203,'sambha',2555656,2449615,'[email protected]'); insert into customer values (204,'rodrix',25757517,2449616,'[email protected]'); insert into customer values (205,'james',25858518,2449617,'[email protected]'); Manager Table insert into manager values('301','unicorn','nick?','tom','jim',2474717,2616166,'[email protected]'); /// insert into manager values('302','phoenix','nick?','ankit','tom',2474717,2616166,'[email protected]'); insert into manager values('303','alpha','nick?','bill','brown',2484818,2636366,'[email protected]'); insert into manager values('304','ceagate','nick?','john','gary',2494919,2646466,'[email protected]'); insert into manager values('305','neon','nick?','lucy','michael',2434313,2656566,'[email protected]'); Fish_details Table insert into fish_details values(401,'rohu','marine',40); /// insert into fish_details values(402,'tuna','salt water',50); insert into fish_details values(403,'roh','salt water',30);

insert into fish_details values(404,'prawn','marine',15); insert into fish_details values(405,'salmon','marine',20); insert into fish_details values(406,'martin','salt water',25); insert into fish_details values(407,'clown','marine',35); Import_cost Tables insert into import_cost values(401,100); insert into import_cost values(402,150); insert into import_cost values(403,200); insert into import_cost values(404,250); insert into import_cost values(405,300); insert into import_cost values(406,350); insert into import_cost values(407,400); Export_price Tables insert into export_price values(401,150); insert into export_price values(402,200); insert into export_price values(403,250); insert into export_price values(404,300); insert into export_price values(405,350); insert into export_price values(406,400); insert into export_price values(407,450); Import_details Tables insert into import_details values(501,401,101,301,'01/nov/11',20); insert into import_details values(502,401,102,303,'02/nov/11',10); insert into import_details values(503,404,103,303,'02/nov/11',12); insert into import_details values(504,405,101,301,'03/nov/11',13); insert into import_details values(505,403,102,304,'04/nov/11',15); insert into import_details values(506,403,103,303,'04/nov/11',10);

insert into import_details values(507,404,104,304,'05/nov/11',20);

Export_deatails: insert into export_details values(601,401,201,301,'01/nov/11',20); insert into export_details values(602,401,204,303,'02/nov/11',10); insert into export_details values(603,404,203,303,'02/nov/11',12); insert into export_details values(604,405,201,301,'03/nov/11',13); insert into export_details values(605,403,204,304,'04/nov/11',15); insert into export_details values(606,403,203,303,'04/nov/11',10); insert into export_details values(607,404,204,304,'05/nov/11',20);

Queries :
1) Display export id, customer name and date of export where customer name starts with s. Select e.ex_id,c.c_name,e.date_export from export_details e INNER JOIN customer c ON e.c_id=c.c_id Where c.c_name like 's%'; 2) Display exporter name, import id, date of import for every import process which should be in ascending order by exporter name. Select i.im_id, e.e_name, i.date_import from exporter e RIGHT OUTER JOIN Import_details i ON e.e_id=i.e_id ORDER BY e.e_name desc; 3) Display export_id, species_name, date_export where species_name should be in ascending order. Select ex_id , species_name, date_export from import_details i LEFT OUTER JOIN fish_details f On i.species_id=f.species_id

Orderby species_name;

4) Display the species id, species name, available quantity in stock and the import cost of fishes. Select f.species_id,f.species_name,i.cost_per_kg from fish_details f FULL OUTER JOIN import_cost i on f.species_id=i.species_id;

5) Display the species id, species name, available quantity in stock and the export price of fishes.

Select f.species_id,f.species_name,f.avail_qty,e.price_per_kg from fish_details f JOIN export_price e ON f.species_id=e.species_id ORDER BY species_id;

6) Display all the details of species of fishes along with its import cost. Select * from fish_details NATURAL JOIN import_cost; 7) Compare export price and import cost of a particular species_id with every other along with its details. Select * from fish_details CROSS JOIN import_cost CROSS JOIN export_price; Select * from fish_details,import_cost,export_price; 8) Display how many combinations of two species share common type. Select a.species_id,a.species_name,b.species_id,b.species_name,b.type from fish_details a INNER JOIN fish_details b ON a.type=b.type; 9) display species id,species name,cost_per_kg using inner join. Select f.species_id,f.species_name,i.cost_per_kg from fish_details f INNER JOIN import_cost i ON f.species_id=i.species_id;

10) display no. of imports for species id 403. Select count(i.im_id) No_of_imports from import_details i,fish_details f where i.species_id=f.species_id group by i.species_id having i.species_id=403;

11) Display the names of all the customers starting from r. select * from customer where c_name like ('r%'); 12) Display the details of all the fish species having fish type salt water or marine. Select * from fish_details where type IN ('salt water','marine') 13) Write a query to select all the fishes imported or exported. Select species_id,cost_per_kg from import_cost UNION Select species_id, price_per_kg from export_price; 14) From all the fish species select those which are not exported. Select species_id from fish_details MINUS Select species_id from export_details; 15) Write a query to select average available quantity of a particular type of species. Select type,avg(avail_qty) from fish_details group by type; 16) Re-write the above query using group by and having clause. Select type,AVG(avail_qty) from fish_details group by type having type IN('marine','salt water');

17) display species_name, available quantity, and cost for fishes which are having maximum cost. Select f.species_name,f.avail_qty,i.cost_per_kg from fish_details f JOIN import_cost i ON f.species_id=i.species_id where i.cost_per_kg= (select max(i.cost_per_kg) from import_cost); 18) show details of fish which is having minimum available quantity. Select * from fish_details where avail_qty= (select min(avail_qty) from fish_details); 19) Write a query to get the number of exports in a particular day. Select count(ex_id) from export_details where date_export='2/nov/11';

20) Select the round cost of fish export in order to pay the taxes. Select round(avg(price_per_kg)) from export_price;

You might also like