2023-01-15:销售员。编写一个SQL查询,报告没有任何与名为 “RED” 的公司相关的订单的所有

2023-01-15:销售员。编写一个SQL查询,报告没有任何与名为 “RED” 的公司相关的订单的所有销售人员的姓名。以 任意顺序 返回结果表。

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

INSERT INTO `company` VALUES ('1', 'RED', 'Boston');
INSERT INTO `company` VALUES ('2', 'ORANGE', 'New York');
INSERT INTO `company` VALUES ('3', 'YELLOW', 'Boston');
INSERT INTO `company` VALUES ('4', 'GREEN', 'Austin');

DROP TABLE IF EXISTS `orders`;
CREATE TABLE `orders` (
  `order_id` int(11) NOT NULL,
  `order_date` date NOT NULL,
  `com_id` int(11) NOT NULL,
  `sales_id` int(11) NOT NULL,
  `amount` int(11) NOT NULL,
  PRIMARY KEY (`order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `orders` VALUES ('1', '2014-01-01', '3', '4', '10000');
INSERT INTO `orders` VALUES ('2', '2014-02-01', '4', '5', '5000');
INSERT INTO `orders` VALUES ('3', '2014-03-01', '1', '1', '50000');
INSERT INTO `orders` VALUES ('4', '2014-04-01', '1', '4', '25000');

DROP TABLE IF EXISTS `sales_person`;
CREATE TABLE `sales_person` (
  `sales_id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `salary` int(11) NOT NULL,
  `commission_rate` int(11) NOT NULL,
  `hire_date` date NOT NULL,
  PRIMARY KEY (`sales_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `sales_person` VALUES ('1', 'John', '100000', '6', '2006-04-01');
INSERT INTO `sales_person` VALUES ('2', 'Amy', '12000', '5', '2010-05-01');
INSERT INTO `sales_person` VALUES ('3', 'Mark', '65000', '12', '2008-12-25');
INSERT INTO `sales_person` VALUES ('4', 'Pam', '25000', '25', '2005-01-01');
INSERT INTO `sales_person` VALUES ('5', 'Alex', '5000', '10', '2005-02-03');

答案2023-01-15:

sql语句如下:

























SELECT
    s.name
FROM
    sales_person s
WHERE
    s.sales_id NOT IN (SELECT
            o.sales_id
        FROM
            orders o
                LEFT JOIN
            company c ON o.com_id = c.com_id
        WHERE
            c.name = 'RED')

在这里插入图片描述

本作品采用《CC 协议》,转载必须注明作者和本文链接
微信公众号:福大大架构师每日一题。最新面试题,涉及golang,rust,mysql,redis,云原生,算法,分布式,网络,操作系统。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!