
192 PUZZLE 48 UNGROUPING
PUZZLE
48 UNGROUPING
Sissy Kubu sent me a strange question on CompuServe. She has a table
like this:
CREATE TABLE Inventory
(goods CHAR(10) NOT NULL PRIMARY KEY,
pieces INTEGER NOT NULL CHECK (pieces >= 0));
She wants to deconsolidate the table; that is, get a VIEW or nontable
with one row for each piece. For example, given a row with ('
CD-ROM', 3)
in the original table, she would like to get three rows with ('
CD-ROM', 1) in
them. Before you ask me, I have no idea why she wants to do this;
consider it a training exercise.
Since SQL has no “
UN-COUNT(*) ... DE-GROUP BY..” operators,
you will have to use a cursor or the vendor’ ...