求:如何查出两个表中不相同的记录?

AOKIO 2007-01-22 01:57:32
例:
如:tableA
id name age
1 aa 22
2 bb 33
3 cc 42
4 dd 55
5 gg 32

tableB
id name age
1 aa 22
2 bb 33
3 cc 44
4 dd 55
5 ee 66
6 ff 77

希望查出结果:

tableA 的
3 cc 42
5 gg 32
tableB 的
5 ee 66
6 ff 77

十分感谢!!!!
...全文
301 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
AOKIO 2007-01-22
  • 打赏
  • 举报
回复
能不能这样呀?比如说,A中有个CC,B中有个CC但是它们age不相同而我只想要一个CC就行.不管后面值改没改变就要那个改变的name应该怎么做呢?
baoshan 2007-01-22
  • 打赏
  • 举报
回复
1 是一个辅助性的查询用法,如果后面的条件成立的话,就返回一个1或一列1 ,通常结合exists 用比较方便
marco08 2007-01-22
  • 打赏
  • 举报
回复
create table A(id int, name varchar(10), age int)
insert A select 1, 'aa', 22
union all select 2, 'bb', 33
union all select 3, 'cc', 42
union all select 4, 'dd', 55
union all select 5, 'gg', 32

create table B(id int, name varchar(10), age int)
insert B select 1, 'aa', 22
union all select 2, 'bb', 33
union all select 3, 'cc', 44
union all select 4, 'dd', 55
union all select 5, 'ee', 66
union all select 6, 'ff' , 77

select id, name, age
from
(
select id, name, age from A
union all
select id, name, age from B
)tmp
group by id, name, age
having count(*)=1

--result
id name age
----------- ---------- -----------
3 cc 42
3 cc 44
5 ee 66
5 gg 32
6 ff 77

(5 row(s) affected)
AOKIO 2007-01-22
  • 打赏
  • 举报
回复
select 1 from A where A.id=B.id and A.name=B.name and A.age=B.age
那个 "1" 是什么意思呀?不明白.谢了~
AOKIO 2007-01-22
  • 打赏
  • 举报
回复
这样不对吧.我要的是查询到两个表中的记录.谢谢你.
marco08 2007-01-22
  • 打赏
  • 举报
回复
create table A(id int, name varchar(10), age int)
insert A select 1, 'aa', 22
union all select 2, 'bb', 33
union all select 3, 'cc', 42
union all select 4, 'dd', 55
union all select 5, 'gg', 32

create table B(id int, name varchar(10), age int)
insert B select 1, 'aa', 22
union all select 2, 'bb', 33
union all select 3, 'cc', 44
union all select 4, 'dd', 55
union all select 5, 'ee', 66
union all select 6, 'ff' , 77

select * from A
where not exists(select 1 from B where A.id=B.id and A.name=B.name and A.age=B.age)

--result
/*
id name age
----------- ---------- -----------
3 cc 42
5 gg 32

(2 row(s) affected)
*/

select * from B
where not exists(select 1 from A where A.id=B.id and A.name=B.name and A.age=B.age)
--result
/*
id name age
----------- ---------- -----------
3 cc 44
5 ee 66
6 ff 77

(3 row(s) affected)
*/
marco08 2007-01-22
  • 打赏
  • 举报
回复

select * from A
where not exists(select 1 from B where A.id=B.id or A.name=B.name or A.age=B.age)
内容概要:本文详细介绍了利用Simulink进行变压器开路试验的电路连接配置与仿真实现方法,重点在于通过仿真手段还原实际电力系统中变压器在空载条件下的电气特性,从而深入理解其工作原理与性能表现。文章作为电力系统仿真系列研究的一部分,系统阐述了从电路模型搭建、参数设定、仿真运行到结果分析的完整流程,突出展示了MATLAB/Simulink在电力设备建模与教学科研中的强大功能与应用价值。; 适合人群:具备电力系统基础知识,熟悉MATLAB/Simulink仿真环境,从事电气工程、自动化及相关领域的研发人员,以及高年级本科生和研究生。; 使用场景及目标:①掌握变压器开路试验的基本原理与Simulink仿真建模的具体步骤;②通过仿真实验深入理解空载电流、铁芯损耗及励磁特性等关键参数的物理意义;③为后续开展变压器短路试验、暂态过程分析以及其他电力设备的仿真研究奠定理论与实践基础。; 阅读建议:建议结合Simulink软件动手实践,逐步构建并调试电路模型,重点关注各元件参数的设置方法与测量模块的应用技巧,同时推荐参考文中提及的其他相关仿真案例进行拓展学习,以全面提升对电力系统仿真实践的整体认知与操作能力。

27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧