/* Mysql> SELECT Name, RatingID AS Rating, -> CASE RatingID -> WHEN 'r'then' Under 17 requires an adult .' -> WHEN 'X' No one 17 and under .' -> WHEN 'nr 'then' Use discretion when refreshing .' -> ELSE 'OK to rent to minors .' -> End as Policy -> FROM DVDs -> Order by Name; + ----------- + -------- + ------------------------------ + | Name | Rating | Policy | + ----------- + -------- + ------------------------------ + | Africa | PG | OK to rent to minors. | | Amadeus | PG | OK to rent to minors. | | Christmas | NR | Use discretion when refreshing. | | Doc | G | OK to rent to minors. | | Falcon | NR | Use discretion when authentication ing. | | Mash | R | Under 17 requires an adult. | | Show | NR | Use discretion when refreshing. | | View | NR | Use discretion when refreshing. | + ----------- + -------- + ------------------------------ + 8 rows in set (0.01 sec) */ Drop table DVDs; Create table DVDs ( Id smallint not null AUTO_INCREMENT primary key, Name VARCHAR (60) not null, NumDisks tinyint not null default 1, RatingID VARCHAR (4) not null, StatID CHAR (3) NOT NULL ) ENGINE = INNODB; Insert into DVDs (Name, NumDisks, RatingID, StatID) VALUES ('Christmas ', 1, 'nr', 's1 '), ('Doc', 1, 'G', 's2 '), ('Africa ', 1, 'pg', 's1 '), ('Falcon ', 1, 'nr', 's2 '), ('Amadeus ', 1, 'pg', 's2 '), ('Show', 2, 'nr ', 's2 '), ('View', 1, 'nr ', 's1 '), ('Mash ', 2, 'R', 's2 '); SELECT Name, RatingID AS Rating, CASE RatingID WHEN 'r'then' Under 17 requires an adult .' WHEN 'X' No one 17 and under .' WHEN 'nr 'then' Use discretion when processing ing .' ELSE 'OK to rent to minors .' End as Policy FROM DVDs Order by Name; |