不明白你的意思
1有AA就没有BB
你查的结果里面怎么1有AA也有BB和
1有AA就没有BB
你查的结果里面怎么1有AA也有BB和
解决方案 »
- 为什么存储过程查询出来的记录不能修改?
- PowerDesinger中有些問題請教(謝謝)
- 这个怎么实现?
- 求一sql查询语句
- 8万多条数据某一字段相加要用多少时间
- C#怎样读取远程数据库的数据,急用,在线等
- SQL中删除一个数据库再建一个数据库的时提示数据库已存在
- 问一些关于SQL Server2000和Oracle报价和用户数的问题
- 我的SQL Server采用Windows登入验证,为什么我一修改Windows(2k)登入密码,SQL就会因登入失败而无法启动
- 安装oracle personal edition,为什么ORA-12541: TNS:no listener?
- 急啊,求自定义一个函数
- 小弟想问一个DTS的问题
select a.id,a.aa,b.bb from 表 a left join 表 b on a.id=b.id
where a.aa is not null and b.bb is not null
select id,aa,0 as myid into #tb1 from 你的表 where isnull(aa,'')<>''
select id,bb,0 as myid into #tb2 from 你的表 where isnull(bb,'')<>''--更新临时表,为数据查询做准备
declare @id int,@myid int
update #tb1 set @myid=case @id when id then @myid+1 else 1 end
,myid=@myid,@id=id
set @id=nullupdate #tb2 set @myid=case @id when id then @myid+1 else 1 end
,myid=@myid,@id=id--从临时表中查询,得到结果
select a.id,isnull(a.aa,'') as aa,isnull(b.bb,'') as bb
from #tb1 a full join #tb2 b on a.myid=b.myid and a.id=b.id--删除临时表
drop table #tb1,#tb2
declare @tb table(ID int,AA varchar(1),BB varchar(1))
insert into @tb
select 1,'x',''
union all select 1,'x',''
union all select 1,'x',''
union all select 1,'','x'
union all select 2,'x',''
union all select 1,'','x'
union all select 2,'x',''
union all select 2,'','x'--为数据处理准备临时表
select id,aa,0 as myid into #tb1 from @tb where isnull(aa,'')<>''
select id,bb,0 as myid into #tb2 from @tb where isnull(bb,'')<>''--更新临时表,为数据查询做准备
declare @id int,@myid int
update #tb1 set @myid=case @id when id then @myid+1 else 1 end
,myid=@myid,@id=id
set @id=nullupdate #tb2 set @myid=case @id when id then @myid+1 else 1 end
,myid=@myid,@id=id--从临时表中查询,得到结果
select a.id,isnull(a.aa,'') as aa,isnull(b.bb,'') as bb
from #tb1 a full join #tb2 b on a.myid=b.myid and a.id=b.id--删除临时表
drop table #tb1,#tb2
----------- ---- ----
1 x x
1 x x
1 x
2 x x
2 x (所影响的行数为 5 行)
姓名ID 迟到时间(包括日期)AA 早退时间(包括日期)BB (一行代表一次考勤)
... ........... ............
... ........... ............
... ........... ............
实际上不是每个人每次都 既迟到又早退,所有表中的 AA 和 BB可能只有一项有值
对表作统计并填充到一个Table中
为了节约表空间,把他们紧凑第排在一起,迟到一列,早退一列,
比如,张三 一共迟到 1次,早退3次,则表为:
----------------------------------
张三 迟到 早退
2月1日 3月1日
3月2日
3月3日
-------------------------
我是想问能不能用select选择出这样的结果来? CrazyFor(太阳下山明朝依旧爬上来) ( ) 的语句,结果行多了,而且该空的地方没有空.不知道有没有可能select出来.