前辈们都还在?问一个问题~

yiyi_wx 2008-01-21 11:54:29

select distinct infant.infantId,infantName,isnull(t.teacherName, '') master,city,country,address,infant.type,t.publicPhone,t.selfPhone,t.Email,t.QQ,postId,isnull(d.teacherCount,0) teacherCount,infant.memo
from infant left join (Select a.* from teacher a where teacherName = (Select top 1 teacherName from teacher where teacherWork = '园长' and infantId=a.infantId)) t on infant.infantId=t.infantId right join (select infantId , count(*) teacherCount from teacher_active b, active c where b.activId = c.activId and c.userId = '1' group by infantId) d on infant.infantId = d.infantId right join infant_active inf_a on infant.infantId = inf_a.infantId inner join active c on inf_a.activid=c.activid where c.activYear between '2006' and '2007' order by infant.infantId


这个语句是可以查出我想要的结果,但刚才突然发现,它会筛选出一行空数据,就是一行为NULL的数据
不知道是我之前没在意,还是刚刚添加的数据有问题
请教一下怎么回事~
谢谢~
...全文
61 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 yiyi_wx 的回复:]
吼吼~
解决了,就是数据有问题
因为之前我改了一部分数据,估计是改乱了,找的头疼

于是我做出了一个英明的决定
我把数据库删了,又重新还原了一下老数据
哈哈,不错了~~
[/Quote]
恭喜啊!
记得:
在每次修改你能成功运行的程序时,一定要先记得备份!
呵呵
  • 打赏
  • 举报
回复
so long
tantaiyizu 2008-01-29
  • 打赏
  • 举报
回复
吼吼~
解决了,就是数据有问题
因为之前我改了一部分数据,估计是改乱了,找的头疼

于是我做出了一个英明的决定
我把数据库删了,又重新还原了一下老数据
哈哈,不错了~~
yiyi_wx 2008-01-22
  • 打赏
  • 举报
回复
吼吼~
解决了,就是数据有问题
因为之前我改了一部分数据,估计是改乱了,找的头疼

于是我做出了一个英明的决定
我把数据库删了,又重新还原了一下老数据
哈哈,不错了~~
yiyi_wx 2008-01-22
  • 打赏
  • 举报
回复
对数据对的头疼
不过还得go on
-狙击手- 2008-01-22
  • 打赏
  • 举报
回复
小依依,睡觉 了

明天见
yiyi_wx 2008-01-22
  • 打赏
  • 举报
回复
嗯,我也觉得是我的数据可能有问题,我先再看看数据
-狙击手- 2008-01-22
  • 打赏
  • 举报
回复
多半你的这些表之间也有做约束或外键关联 吧


可能是记录不完整吧,比如infant 这的老师在teacher中却不存在
yiyi_wx 2008-01-21
  • 打赏
  • 举报
回复
上面那个不好看,在发一个

select distinct infant.infantId,infantName,isnull(t.teacherName, '') master,city,country,address,infant.type,t.publicPhone,t.selfPhone,t.Email,t.QQ,postId,isnull(d.teacherCount,0) teacherCount,infant.memo
from infant
left join (Select a.* from teacher a where teacherName = (Select top 1 teacherName from teacher where teacherWork = '园长' and infantId=a.infantId)) t on infant.infantId=t.infantId
right join (select infantId , count(*) teacherCount from teacher_active b, active c where b.activId = c.activId and c.userId = '1' group by infantId) d on infant.infantId = d.infantId
right join infant_active inf_a on infant.infantId = inf_a.infantId
inner join active c on inf_a.activid=c.activid
where c.activYear between '2006' and '2007' order by infant.infantId


34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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