tutorial4-sol - Problem 1: SQL Aggregation Write the...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Problem 1: SQL Aggregation Write the requested SQL queries for each part of this problem. You may (and should) use any aggregation functions you wish. If you feel like you have to make any assumptions, note them explicitly. Consider the following schema: Camera(model , manufacturer, type, price) , shutter_speed, zoom, internal_memory) SLR(model , shutter_speed, internal_memory) 1. Rewrite the following query as simply as possible, without using DISTINCT: Select Distinct manufacturer From Camera; Solution: Select manufacturer From Camera Group By manufacturer; 2. List the camera models, in alphabetical order, which have the minimum price. You may not assume that all models have a different price - in other words, it may be possible that multiple models all have the minimum price. Solution: Select model From Camera Where price <= (Select Min(price) From Camera)) Order By model 3. Find how many camera models are neither P&S's nor SLR's. In other words, give the number of models which are in Camera, but not found in either of the other relations. Solution: Select count\(*) From( (Select model From Camera) Except ((Select model From P&S) Union (Select model from SLR)) ); 4. Give the manufacturer(s), in alphabetical order, which produces the largest number of camera models. Do not assume that the answer will necessarily be unique - it may be the case that there are multiple manufacturers that produce the same largest number. Solution: Select manufacturer From Camera Group By manufacturer Having Count(model) >= All (Select Count(model) From Camera Group By manufacturer) Order By manufacturer;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Problem 2: Modifications and Views Consider a modified version of the schema from problem 1, this time concerning the customers who purchase cameras:
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/17/2012 for the course CS 411 taught by Professor Winslett during the Spring '07 term at University of Illinois at Urbana–Champaign.

Page1 / 5

tutorial4-sol - Problem 1: SQL Aggregation Write the...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online