Introduction To Database Systems CSE 444: Lecture 3: SQL (Part 2)
Introduction To Database Systems CSE 444: Lecture 3: SQL (Part 2)
CSE 444
We probably want:
SELECT product,
sum(quantity) AS SumQuantity,
max(price) AS MaxPrice
FROM Purchase
GROUP BY product
SELECT Author.name
FROM Author, Wrote This is
WHERE Author.login=Wrote.login SQL by
GROUP BY Author.name an expert
HAVING count(wrote.url) > 10
Store(sid, sname)
Product(pid, pname, price, sid)
But we need the witnesses, i.e. the products with max price
SELECT * E.g.
FROM Person age=20
WHERE (age < 25) AND height=NULL
(height > 6 OR weight > 190) weight=200
SELECT *
FROM Person
WHERE age < 25 OR age >= 25
SELECT *
FROM Person
WHERE age < 25 OR age >= 25 OR age IS NULL
Name Store
Gizmo Wiz
Camera Ritz
Camera Wiz
OneClick NULL
Application
• Compute, for each product, the total number of sales in
‘September’
Product(name, category)
Purchase(prodName, month, store)
What’s wrong ?
Magda Balazinska - CSE 444, Fall 2010
Application
• Compute, for each product, the total number of sales in
‘September’
Product(name, category) Need to use
Purchase(prodName, month, store) attribute to
get correct
zero count
SELECT Product.name, count(store) (6.4.6)
FROM Product LEFT OUTER JOIN Purchase ON
Product.name = Purchase.prodName
and Purchase.month = ‘September’
GROUP BY Product.name