2022-12-15:寻找用户推荐人。写一个查询语句,返回一个客户列表,列表中客户的推荐人的编号都 不是 2。 对于示例数据,结果为: +------+ | name | +------+ | Will | | Jane | | Bill | | Zack | +------+

DROP TABLE IF EXISTS `customer`;
CREATE TABLE `customer` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `referee_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `customer` VALUES ('1', 'Will', null);
INSERT INTO `customer` VALUES ('2', 'Jane', null);
INSERT INTO `customer` VALUES ('3', 'Alex', '2');
INSERT INTO `customer` VALUES ('4', 'Bill', null);
INSERT INTO `customer` VALUES ('5', 'Zack', '1');
INSERT INTO `customer` VALUES ('6', 'Mark', '2');

答案2022-12-15: sql语句如下:

SELECT name FROM customer WHERE referee_id != 2 OR referee_id IS NULL;

在这里插入图片描述