《MysqL必读MysqL的CASE WHEN语句的几个使用实例》要点:
本文介绍了MysqL必读MysqL的CASE WHEN语句的几个使用实例,希望对您有用。如果有疑问,可以联系我们。
MysqL数据库使用CASE WHEN进行字符串替换处置
MysqL数据库9 rows in set (0.01 sec)
MysqL数据库SELECT name AS name,
CASE category
WHEN "HolIDay" THEN "Seasonal"
WHEN "Profession" THEN "Bi_annual"
WHEN "literary" THEN "Random" END AS "Pattern"
FROM sales;
MysqL数据库9 rows in set (0.00 sec)
MysqL数据库CREATE table sales(
num MEDIUMINT NOT NulL auto_INCREMENT,name CHAR(20),winter INT,spring INT,
su妹妹er INT,fall INT,category CHAR(13),primary key(num)
) ENGINE=MyISAM;
MysqL数据库insert into sales value(1,'Java',1067,200,150,267,'HolIDay');
insert into sales value(2,'C',970,770,531,486,'Profession');
insert into sales value(3,'JavaScript',53,13,21,856,'literary');
insert into sales value(4,'sql',782,357,168,250,'Profession');
insert into sales value(5,'Oracle',589,795,367,284,'HolIDay');
insert into sales value(6,'MysqL',953,582,336,489,'literary');
insert into sales value(7,'Cplus',752,657,259,478,'literary');
insert into sales value(8,'Python',67,23,83,543,'HolIDay');
insert into sales value(9,'PHP',673,48,625,52,'Profession');
简单语句
代码以下:
SELECT CASE WHEN 10*2=30 THEN '30 correct'
WHEN 10*2=40 THEN '40 correct'
ELSE 'Should be 10*2=20'
END AS `result`;
多重表达式
代码以下:SELECT CASE 10*2
WHEN 20 THEN '20 correct'
WHEN 30 THEN '30 correct'
WHEN 40 THEN '40 correct'
ELSE 'No results'
END AS `result`;
在SELECT查询中使用CASE WHEN
代码以下: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','G', 's2'),('Africa','PG',('Falcon','s2'),
('Amadeus',('Show',2,('VIEw',('Mash','R', 's2');
SELECT name,ratingID AS rating,
CASE ratingID
WHEN 'R' THEN 'Under 17 requires an adult.'
WHEN 'X' THEN 'No one 17 and under.'
WHEN 'NR' THEN 'Use discretion when renting.'
ELSE 'OK to rent to minors.'
END AS Policy
FROM DVDs
ORDER BY name;
MysqL数据库8 rows in set (0.01 sec)
欢迎参与《MysqL必读MysqL的CASE WHEN语句的几个使用实例》讨论,分享您的想法,内存溢出 jb51.cc为您提供专业教程。
总结以上是内存溢出为你收集整理的Mysql必读MySQL的CASE WHEN语句的几个使用实例全部内容,希望文章能够帮你解决Mysql必读MySQL的CASE WHEN语句的几个使用实例所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)