


























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Various sql techniques including different types of joins, subqueries, programming standard functions, financial functions, and text file input/output operations. It includes examples of how to use subqueries for calculations, correlated subqueries, and recursive joins in sql. It also discusses programming concepts such as the case function, iif function, and select case statement. The document also covers various sql programming standard functions, financial functions, and text file input/output operations.
Typology: Slides
1 / 66
This page cannot be seen from the preview
Don't miss anything!
1
2
4
5
7
SELECT Customer.LastName, Customer.FirstName, SaleItem.ItemID FROM (Customer INNER JOIN Sale ON Customer.CustomerID = Sale.CustomerID) INNER JOIN SaleItem ON Sale.SaleID = SaleItem.SaleID WHERE (SaleItem.ItemID In (1,2,30,32,33)) ORDER BY Customer.LastName, Customer.FirstName;
Query05_Fig
SaleID SaleDate EmployeeID CustomerID
Field LastName FirstName ItemID Table Customer Customer SaleItem
Sort Ascending Ascending Criteria In (1,2,30,32,33) Or
CustomerID Phone FirstName LastName
SaleID ItemID Quantity SalePrice
List all customers who bought items for cats.
8
SELECT Customer.LastName, Customer.FirstName, SaleItem.ItemID FROM (Customer INNER JOIN Sale ON Customer.CustomerID = Sale.CustomerID) INNER JOIN SaleItem ON Sale.SaleID = SaleItem.SaleID WHERE (SaleItem.ItemID In (SELECT ItemID FROM Merchandise WHERE Category=‘Cat’) );
Query05_Fig
10
Query05_Fig
Any: value is compared to each item in the list. If it is True for any of
the items, the statement is evaluated to True.
All: value is compared to each item in the list. If it is True for every item
in the list, the statement is evaluated to True (much more restrictive than any.
11
Query05_Fig
13
ID Name Category Breed 2 Fish Angel 4 Gary Dog Dalmation 5 Fish Shark 6 Rosie Cat Oriental Shorthair 7 Eugene Cat Bombay 8 Miranda Dog Norfolk Terrier 9 Fish Guppy 10 Sherri Dog Siberian Huskie 11 Susan Dog Dalmation 12 Leisha Dog Rottweiler
ID SaleID SalePrice 2 35 $10. 4 80 $156. 6 27 $173. 7 25 $251. 8 4 $183. 10 18 $150. 11 17 $148.
AnimalID 2 4 12 19 25 34 88 181
Name
Simon Leisha Gene Vivian Rhonda Brandy
Category Fish Dog Dog Dog Dog Dog Dog Fish
14
SELECT Animal.AnimalID, Animal.Name, Animal.Category FROM Animal LEFT JOIN SaleAnimal ON Animal.AnimalID = SaleAnimal.AnimalID WHERE (SaleAnimal.SaleID Is Null);
SaleID AnimalID SalePrice
Field AnimalID SaleID Name Category
Table Animal SaleAnimal Animal Animal
Sort
Criteria Is Null
Or
AnimalID Name Category Breed
Query05_Fig
16
Old Oracle syntax— note that the (+) symbol is on the reversed side.
17
SELECT SaleAnimal.AnimalID, Animal.Category, SaleAnimal.SalePrice FROM Animal INNER JOIN SaleAnimal ON Animal.AnimalID = SaleAnimal.AnimalID WHERE ((Animal.Category=‘ Cat’ ) AND (SaleAnimal.SalePrice> ( SELECT AVG(SalePrice) FROM Animal INNER JOIN SaleAnimal ON Animal.AnimalID = SaleAnimal.AnimalID WHERE (Animal.Category=‘ Cat ’) ) ) );
SaleID AnimalID SalePrice
Field AnimalID Name Category SalePrice
Table Animal Animal Animal SaleAnimal
Sort Descending
Criteria 3 > (SELECT Avg(SalePrice) FROM Animal INNER JOIN SaleAnimal ON Animal.AnimalID = SaleAnimal.AnimalID WHERE Animal.Category = ‘Cat’)
Or
AnimalID Name Category Breed
Query05_Fig
19
SELECT A1.AnimalID, A1.Name, A1.Category, SaleAnimal.SalePrice FROM Animal As A1 INNER JOIN SaleAnimal ON A1.AnimalID = SaleAnimal.AnimalID WHERE (SaleAnimal.SalePrice> (SELECT Avg(SaleAnimal.SalePrice) FROM Animal As A2 INNER JOIN SaleAnimal ON A2.AnimalID = SaleAnimal.AnimalID WHERE (A2.Category = A1.Category) ) ) ORDER BY SaleAnimal.SalePrice DESC;
Query05_Fig
20
Fish $10. Dog $156. Fish $19. Cat $173. Cat $251. Dog $183. Fish $1. Dog $150. Dog $148.
Category SalePrice