大神帮忙看下配置曙光医院可不可以纹眉行!谢谢!

查看: 4464|回复: 20
[sqlserver]怎么单表查询具多个相同字段值都不重复的列
沧海ふ无涯
本帖最后由 沧海ふ无涯 于
15:13 编辑
QQ截图26.png (81.92 KB, 下载次数: 0)
10:17 上传
其实,这是一张教室的申请表.cycletime week&&section 以及roomid 分别表示 周次 星期 节次&&和教室ID
这四个属性决定了所申请的具体时间节点的教室.
现在我要找出所有某个时间点只有一次申请的教室.这些申请都是可以自动审核通过的,因为是没有冲突的嘛...
我现在的想法就是循环遍历每一条数据然后在where匹配表里的所有记录.
这样的话,会很复杂,如果有N条数据,就要查询N*(N-1)次.
一句话就是:查询 roomid,[cycletime],[week],section这四个字段不完全相同的列并显示其ID
select id from apply where id not in (select a1.id from apply a1,apply a2 where (a1.id&&a2.id and a1.cycletime=a2.cycletime and a1.[week]=a2.[week] and a1.section=a2.section and a1.roomid=a2.roomid) )
本帖最后由 cis 于
12:41 编辑
能用就行了,还优化什么
本帖最后由 peng 于
14:33 编辑
是否要这样?
select roomid from xx group by week having count(id)=1
以星期分组&&统计组里id个数=1的教室
???没有具体时间点???你这数据表截齐点
沧海ふ无涯
能用就行了,还优化什么
有点追求好么,你这样的态度人家小餐馆都不愿意用你
沧海ふ无涯
是否要这样?
select roomid from xx group by week having count(id)=1
以星期分组&&统计组里id个数=1的 ...
你没看我的说明.........时间不是有的么...
周次星期和节次来表示的
我更新了帖子&&写了个不怎么好的代码
沧海ふ无涯
本帖最后由 沧海ふ无涯 于
14:40 编辑
是否要这样?
select roomid from xx group by week having count(id)=1
以星期分组&&统计组里id个数=1的 ...
网络问题 重复了
沧海ふ无涯
本帖最后由 沧海ふ无涯 于
14:40 编辑
是否要这样?
select roomid from xx group by week having count(id)=1
以星期分组&&统计组里id个数=1的 ...
网络问题 重复了
沧海ふ无涯
本帖最后由 沧海ふ无涯 于
14:40 编辑
是否要这样?
select roomid from xx group by week having count(id)=1
以星期分组&&统计组里id个数=1的 ...
网络问题 重复了
沧海ふ无涯
本帖最后由 沧海ふ无涯 于
14:40 编辑
是否要这样?
select roomid from xx group by week having count(id)=1
以星期分组&&统计组里id个数=1的 ...
网络问题 重复了
沧海ふ无涯
本帖最后由 沧海ふ无涯 于
14:39 编辑
是否要这样?
select roomid from xx group by week having count(id)=1
以星期分组&&统计组里id个数=1的 ...
网络问题 重复了
Copyright & KaFan & All Rights Reserved.
Powered by Discuz! X3.1( 苏ICP备号 ) GMT+8,SQL语句技巧:查询存在一个表而不在另一个表中的数据记录 -
文俊IT社区
SQL语句技巧:查询存在一个表而不在另一个表中的数据记录
浏览(5196)
方法一(仅适用单个字段)
使用 not in ,容易理解,效率低
select A.ID from A where A.ID not in (select ID from B)
方法二(适用多个字段匹配)
使用 left join...on... , &B.ID isnull& 表示左连接之后在B.ID 字段为 null的记录
select A.ID from A left join B on A.ID=B.ID where B.ID is null&
方法三(适用多个字段匹配)
select * from B where (select count(1) as num from A where A.ID = B.ID) = 0
方法四(适用多个字段匹配)
select * from A where not exists(select 1 from B where A.ID=B.ID)查看: 6809|回复: 2
如何(急)用一个SQL语句查询多个表的记录数总和
论坛徽章:0
如何用一个SQL语句查询多个表的记录数总和 ,在SQL Server中可以使用:
select test=(select count(*)&&from test1)+(select count(*) from test2)
但在oracle中如何实现,谢谢!
论坛徽章:63
select a1.c1+a2.c2 from
&&(select count(*) c1 from tab) a1,
&&(select count(*) c2 from tab) a2
论坛徽章:0
谢谢楚香帅!
itpub.net All Right Reserved. 北京皓辰网域网络信息技术有限公司版权所有    
 北京市公安局海淀分局网监中心备案编号: 广播电视节目制作经营许可证:编号(京)字第1149号温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(3390)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'如何用sql语句查询和删除表中重复数据',
blogAbstract:'1、查询表中重复数据(单字段)Select * From 表 Where 字段1 In (Select 字段1 From 表 Group By 字段1 Having Count(字段1) & 1)
2、删除表中多余的重复记录,只留有rowid最小的记录(单字段)Delete From 表Where 字段1 In (Select 字段1 From 表 Group By 字段1 Having Count(字段1) & 1) And&& Rowid Not In (Select Min(Rowid) From 表 Group By 字段1 Having Count(字段1) & 1)&&&&&
3、查找表中多余的重复记录(多个字段)',
blogTag:'字段,select,count,group,rowid',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:0,
publishTime:5,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}

我要回帖

更多关于 波斯猫可不可以配置 的文章

 

随机推荐