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