We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
写一条SQL 查询语句获取 sales 表中所有产品对应的 产品名称 product_name 以及该产品的所有 售卖年份 year 和 价格 price 。
sales
产品名称 product_name
售卖年份 year
价格 price
sale_id
year
product_id
product
CREATE TABLE sales ( sale_id INT, product_id INT, year INT, quantity INT, price INT ); INSERT INTO sales ( sale_id, product_id, year, quantity, price ) VALUES ( '1', '100', '2008', '10', '5000' ), ( '2', '100', '2009', '12', '5000' ), ( '7', '200', '2011', '15', '9000' ); CREATE TABLE product ( product_id INT, product_name VARCHAR ( 10 ) ); INSERT INTO product ( product_id, product_name ) VALUES ( '100', 'Nokia' ), ( '200', 'Apple' ), ( '300', 'Samsung' );
所以方法一和方法二都是使用这种方法的不同形式。
select product_name, year, price from sales join product using(product_id)
使用 join 方法连接两张表,连接条件是 product_id 。
join
select product_name, year, price from sales, product where sales.product_id = product.product_id
两表查询,通过 where 连接两张表之间的 product_id。
where
The text was updated successfully, but these errors were encountered:
No branches or pull requests
题目
写一条SQL 查询语句获取
sales
表中所有产品对应的产品名称 product_name
以及该产品的所有售卖年份 year
和价格 price
。sale_id
,year
) 是销售表sales
的主键sales
表中的product_id
是关联到产品product
的外键product
表中的product_id
是主键分析:
sales
表中的外键product_id
和product
表中的主键product_id
做关联所以方法一和方法二都是使用这种方法的不同形式。
SQL:方法一
解析
使用
join
方法连接两张表,连接条件是product_id
。SQL:方法二
解析
两表查询,通过
where
连接两张表之间的product_id
。The text was updated successfully, but these errors were encountered: