/* Mysql> SELECT Name, ratingid as Rating, -> Case Ratingid -> when ' R ' THEN ' Under requires a adult. ' -> when ' X ' THEN ' No one and under. ' -> when ' NR ' THEN ' with discretion when renting. ' -> 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 renting. | | Doc | G | OK to rent to minors. | | Falcon | NR | Use discretion when renting. | | Mash | R | Under requires an adult. | | Show | NR | Use discretion when renting. | | View | NR | Use discretion when renting. | +-----------+--------+------------------------------+ 8 rows in Set (0.01 sec) */ Drop table DVDs; CREATE TABLE DVDs ( ID SMALLINT not NULL auto_increment PRIMARY KEY, Name VARCHAR 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 requires a adult. ' When ' X ' THEN ' No one and under. ' When ' NR ' THEN ' with discretion when renting. ' ELSE ' OK to rent to minors. ' End as Policy From DVDs Order BY Name; |