1.將Sql語句的查詢字段進行判斷(case when)
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------sql語句
-- Table structure for test
-- ----------------------------
DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
`fid` int(10) DEFAULT NULL,
`fname` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of test
-- ----------------------------
INSERT INTO `test` VALUES ('1', '登錄');
INSERT INTO `test` VALUES ('1', '注冊');
INSERT INTO `test` VALUES ('1', '退出');
INSERT INTO `test` VALUES ('2', '登錄');
INSERT INTO `test` VALUES ('2', '注冊');
INSERT INTO `test` VALUES ('2', '退出');
INSERT INTO `test` VALUES ('2', '修改');
INSERT INTO `test` VALUES ('2', '百度');
INSERT INTO `test` VALUES ('3', '登錄');
INSERT INTO `test` VALUES ('3', '注冊');
INSERT INTO `test` VALUES ('3', '退出');
INSERT INTO `test` VALUES ('3', '修改');
INSERT INTO `test` VALUES ('3', '百度');
INSERT INTO `test` VALUES ('3', '新浪');
INSERT INTO `test` VALUES ('3', '司機');
2.操作語句
SELECT CASE test.fid
WHEN 1 THEN '免費版'
WHEN 2 THEN '標準版'
ELSE '旗艦版' END
as testCol,
test.fid tid
from test