Consider the schema Grades(id,grade), where grades are in between 0 and 100. Write a query that computes the histogram of the form



This problem is not as easy as it sounds.



CREATE VIEW Score (score) AS
SELECT floor(grade/10)
FROM Grades
SELECT score, COUNT(*)
FROM Score
GROUP BY score
ORDER BY DESC score


Note: This is only a partial solution, since, say, if 0 people got 20-29, it misses the pair
h2 0i. For a complete solution, we can create a constant table, DummyScores, with
the attribute score and the following tuples: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
(each number is a tuple by itself). Then we can proceed as follows:


CREATE VIEW Score1 (score) AS
(SELECT floor(grade/10)
FROM Grades)
UNION
(SELECT * FROM DummyScores)
SELECT score, COUNT(*)-1
FROM Score1
GROUP BY score
ORDER BY DESC score


This solution is correct because DummyScores adds 1 to the count of every score in the
histogram, which we correct by subtracting 1 in the second query.

Computer Science & Information Technology

You might also like to view...

Case 9-2 Sarah is preparing the annual financial report of her company using Microsoft Word 2016. While reviewing the report, Sarah accidently closes it. She wants to open the recently closed file. To do this, Sarah should click the Open option in the _____ in Backstage view.

A. ?navigation bar B. ?Mini toolbar C. ?review pane D. ?View tab

Computer Science & Information Technology

The Picture Size Mode property determines the size of the picture in the form. The ________ setting retains the original size of the image

A) Clip B) Picture Type property C) Zoom D) Stretch

Computer Science & Information Technology

The Option ________ statement in Access is used in a module to require that all variables be declared before they are used

A) On Load B) Explicit C) Compare Database D) Property

Computer Science & Information Technology

In a ____ copy, two or more pointers have their own data.

A. shallow B. deep C. static D. dynamic

Computer Science & Information Technology