两表关联查询SQL语句的,要怎么写?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了两表关联查询SQL语句的,要怎么写?相关的知识,希望对你有一定的参考价值。
参考技术A1、创建测试表;
create table company(companyId number, companyName varchar2(20), contacts varchar2(20));
create table users(userId number, companyId number, userName varchar2(20), userAge number, address varchar2(20));
2、插入测试数据;
insert into company values (1,'腾讯科技','马化腾');
insert into company values (2,'微软公司','鲍威尔');
insert into company values (3,'新浪科技','小明' );
insert into users values (1,1,'jack',23 , '上海');
insert into users values (2,1,'jack2', 23, '上海');
insert into users values (3,2,'jack3', 23, '上海');
insert into users values (4,2,'jack4', 23, '上海');
insert into users values (5,3,'jack5', 23, '上海');
insert into users values (6,3,'jack6', 23, '上海');
3、查询表中数据;
select * from users;
4、编写sql,关联两张表;select * from users t , company b where t.companyid = b.companyid and t.companyid = 1;
sql语句 两表关联查询计算数量
select sum(a1.`num`) from `order_orderlistrow` as a1 INNER JOIN `order_orderlist` as a2 on a1.`order_orderlist_id` = a2.`id` where a1.`goods_good_id` =‘54‘ and a2.`state` <> ‘0‘
以上是关于两表关联查询SQL语句的,要怎么写?的主要内容,如果未能解决你的问题,请参考以下文章