这是什么规律?只是对MID排序吗,也不像阿!
解决方案 »
- sql2005 数据查询占用cpu过大的问题该如何解决
- SQL Server怎么样实现图片(Image)的读入和显示,不用VC,VB等程序实现
- 最大值问题
- sql server 2005 数据库邮件 发送报错Query execution failed: Sqlcmd: Error: Microsoft SQL N
- 无法清除日志
- "select 标题 from 基本信息 where 作者=张秀" 这条语句错在哪里?
- SQL如何实现以下数据统计查询
- 那位大虾知道网上哪里有sqlserver的函数的参考手册?
- 如何使用命令行执行一个sql文件
- 求数据库系统概念这本书的第五版
- 求助在查询管理器或管理工具中的一个问题.
- 求sql循环插入脚本.
union
select * from Card
union all
select * from Card)T order by T.cid
mid cid
---------- ----------
01 111
01 222
01 333
01 789
02 111
02 222
02 456
02 789 (所影响的行数为 8 行)
*/
select * from cselect distinct m.mid, c.cid from m, c where convert(char(10), m.mid) + convert(char(10), c.cid) not in (select convert(char(10), m.mid) + convert(char(10), m.cid) from m)/*
mid cid
---------- ----------
01 123
02 123
01 456
02 333 (所影响的行数为 4 行)cid
----------
123
456
789
111
222
333 (所影响的行数为 6 行)mid cid
---------- ----------
01 111
01 222
01 333
01 789
02 111
02 222
02 456
02 789 (所影响的行数为 8 行)
*/
CREATE TABLE #Machine(MID char(10),CID char(10))
CREATE TABLE #Card(CID char(10))insert into #Machine
select '01','123'
union all
select '02','123'
union all
select '01','456'
union all
select '02','333'
insert #Card
select '123'
union all
select '456'
union all
select '789'
union all
select '111'
union all
select '222'
union all
select '333'--执行语句
select a.mid,b.cid from (select distinct mid from #Machine) a inner join #card b on 1=1 where b.cid not in (select cid from #Machine where mid =a.mid)
order by a.mid