006--SQL语句select加判断

1.判断加别名

SELECT  IF(1<2,'yes ','no') as FLAG; 

2.判断范围:

SELECT
ctest.CID,
ctest.CName,
IF(ctest.CID in (1,2,3,4),'yes ','no') AS CFLAG
from ctest 

  • SQL语句
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for ctest
-- ----------------------------
DROP TABLE IF EXISTS `ctest`;
CREATE TABLE `ctest` (
  `CID` int(20) NOT NULL AUTO_INCREMENT,
  `CName` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`CID`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of ctest
-- ----------------------------
INSERT INTO `ctest` VALUES ('1', '1');
INSERT INTO `ctest` VALUES ('2', '2');
INSERT INTO `ctest` VALUES ('3', '3');
INSERT INTO `ctest` VALUES ('4', '4');
INSERT INTO `ctest` VALUES ('5', '5');
INSERT INTO `ctest` VALUES ('6', '6');
INSERT INTO `ctest` VALUES ('7', '7');
INSERT INTO `ctest` VALUES ('8', '8');
INSERT INTO `ctest` VALUES ('9', '9');
INSERT INTO `ctest` VALUES ('10', '10');

你可能感兴趣的:(006--SQL语句select加判断)