2022-11-17:组合两个表。请写出sql语句,执行结果是{“headers“: [“first_nam

2022-11-17:组合两个表。请写出sql语句,执行结果是{“headers”: [“first_name”, “last_name”, “city”, “state”], “values”: [[“Allen”, “Wang”, null, null], [“Bob”, “Alice”, “New York City”, “New York”]]}。
两张表的sql语句如下:

DROP TABLE IF EXISTS `address`;
CREATE TABLE `address` (
  `address_id` int(11) NOT NULL,
  `person_id` int(11) NOT NULL,
  `city` varchar(255) NOT NULL,
  `state` varchar(255) NOT NULL,
  PRIMARY KEY (`address_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `address` VALUES ('1', '2', 'New York City', 'New York');
INSERT INTO `address` VALUES ('2', '3', 'Leetcode', 'California');

DROP TABLE IF EXISTS `person`;
CREATE TABLE `person` (
  `person_id` int(11) NOT NULL,
  `first_name` varchar(255) NOT NULL,
  `last_name` varchar(255) NOT NULL,
  PRIMARY KEY (`person_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `person` VALUES ('1', 'Allen', 'Wang');
INSERT INTO `person` VALUES ('2', 'Bob', 'Alice');

答案2022-11-17:
sql语句如下:

select first_name, last_name, city, state
from person left join address
on person.person_id = address.person_id

在这里插入图片描述

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

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