insert into 如何不重复数据

youzheng0079 2008-05-19 04:30:54
现有两表
表a
mid 门店
1 aa
2 bb
3 cc
4 dd
5 ee
6 ff
7 gg
8 hh

表b
mid 门店
1 aa
2 bb
3 cc
7 gg
8 hh
9 ii
10 jj
11 kk
现从表b向表a添加数据.请问如何不会重复添加
想要的结果:
表a
mid 门店
1 aa
2 bb
3 cc
4 dd
5 ee
6 ff
7 gg
8 hh
9 ii
10 jj
11 kk
...全文
1184 5 打赏 收藏 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
dawugui 2008-05-19
  • 打赏
  • 举报
回复
--1
insert into A select * from B where 门店 not in (select 门店 from A)
--2
insert into A select * from B where not exists (select 1 from A where mid = B.mid and 门店 = B.门店)
Limpire 2008-05-19
  • 打赏
  • 举报
回复
--> 测试数据: #a
if object_id('tempdb.dbo.#a') is not null drop table #a
create table #a (mid int,门店 varchar(2))
insert into #a
select 1,'aa' union all
select 2,'bb' union all
select 3,'cc' union all
select 4,'dd' union all
select 5,'ee' union all
select 6,'ff' union all
select 7,'gg' union all
select 8,'hh'
--> 测试数据: #b
if object_id('tempdb.dbo.#b') is not null drop table #b
create table #b (mid int,门店 varchar(2))
insert into #b
select 1,'aa' union all
select 2,'bb' union all
select 3,'cc' union all
select 7,'gg' union all
select 8,'hh' union all
select 9,'ii' union all
select 10,'jj' union all
select 11,'kk';

-->如果门店不重复
insert into #a select * from #b where not exists (select 1 from #a where 门店=#b.门店)

select * from #a
/*
mid 门店
----------- ----
1 aa
2 bb
3 cc
4 dd
5 ee
6 ff
7 gg
8 hh
9 ii
10 jj
11 kk
*/
sweetweiwei 2008-05-19
  • 打赏
  • 举报
回复
insert into a select * from b where not exists (select 1 from a where mid=b.mid
lff642 2008-05-19
  • 打赏
  • 举报
回复

--try
insert into a select * from b where mid not in (select mid from a)

Limpire 2008-05-19
  • 打赏
  • 举报
回复
insert into a select * from b where not exists (select 1 from a where mid=b.mid)
代码转载自:https://pan.quark.cn/s/a4b39357ea24 自动驾驶是当前科技界高度关注的研究方向,其研究范畴涵盖了人工智能、计算机视觉、机器学习以及传感器融合等多个重要学科。这份题为"自动驾驶论文"的资料,无疑为人们提供了一个深入了解这一复杂系统的机会。以下是基于其标题和描述所呈现的一些关键知识点的详细阐述: 1. **自动驾驶技术**:自动驾驶指的是车辆在无需人类驾驶员参与的情况下,借助各类传感器和智能算法来感知周围环境,制定行驶路线,并执行驾驶行为。这种技术的核心宗旨在于提升交通安全性、缓解交通压力,并改善出行体验。 2. **Python编程语言**:Python是一种在数据处理和科学计算领域得到广泛应用的高级编程语言,由于其语法简洁且拥有丰富的库支持,经常被应用于自动驾驶领域的数据处理、模型构建和系统集成。 3. **源代码分析**:论文中提供的源代码可能包含了自动驾驶算法的实现细节,可能涵盖环境感知模块(包括图像处理、激光雷达数据解读)、决策模块(涉及路径规划、行为分析)、控制模块(涵盖车辆动力学建模、控制策略设计)等,这些代码可作为学习和研究自动驾驶算法的实践范例。 4. **计算机视觉**:自动驾驶系统中的计算机视觉技术主要用于识别道路标识、行人、其他车辆等,这通常涉及图像分类、目标识别和语义分割等任务,常见的技术包括卷积神经网络(CNN)、区域提议网络(RPN)、YOLO、Faster R-CNN等。 5. **机器学习**:机器学习是自动驾驶技术的核心,用于训练模型以理解和预测复杂的驾驶情境。深度学习,特别是深度强化学习,在决策制定和控制策略方面已取得显著进展。 6. **传感器融合**:自动驾驶汽车通常装备多种传...

22,298

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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