這個問題無法由SQLServer自動解決的。

創(chuàng)新互聯(lián)專注于右玉網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供右玉營銷型網(wǎng)站建設(shè),右玉網(wǎng)站制作、右玉網(wǎng)頁設(shè)計、右玉網(wǎng)站官網(wǎng)定制、微信小程序開發(fā)服務(wù),打造右玉網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供右玉網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
想要解決的話。一種辦法是取消字段的自動增長,寫【instead of 觸發(fā)器】,但是相對于大量的表來說這種方式耗時間,且觸發(fā)器過多會影響SQLServer性能。
但是序號不連續(xù)的數(shù)據(jù)并不影響你的sql語句操作的,沒有特殊需要的話,不要糾結(jié)序號的連續(xù)
以下以2013年11月為例
1、使用橫向連接,以5天為例,簡單但不易擴展
with data as ( select * from yourtable where date='2013-11-01' and date'2013-12-01')
select distinct name
from data t1 join data t2 on t1.name=t2.name and t1.date=t2.date+1
join data t3 on t2.name=t3.name and t2.date=t3.date+1
join data t4 on t3.name=t4.name and t3.date=t4.date+1
join data t5 on t4.name=t5.name and t4.date=t5.date+1
2、使用縱向分組統(tǒng)計
with t1(id,rq) as (
select distinct 人員, date from 表 where date='2013-11-01' and date'2013-12-01' ),
--t1求出指定月的人員編號及不同的打卡日期
t2 as (select s2.* from t1 s1 join t1 s2 on s1.id=s2.id and s1.rq=s2.rq-1),
--t2求出所有上一日也打過卡的日期
t3 as (select * from t1 except select * from t2),
--t3求出所有上一日未打過卡的日期
t as (
select id,rq,1 days from t3
union all
select t1.id,t1.rq,t.days+1 from t1 join t on t1.id=t.id and t1.rq=t.rq+1
)
--t4遞歸調(diào)用,每連續(xù)一日days+1,就是求每一打卡時間是連續(xù)的第幾天
select id
from t
group by id
having max(days)=5
order by id
以上就不刪了,以下可以改短點吧
with t as (
select 人員 id, date rq, 1 days from 表 t1
where not exists(select * from 表 t2 where t2.date=t1.date-1)
union all
select t1.id,t1.rq,t.days+1 from 表 t1 join t on t1.id=t.id and t1.rq=t.rq+1
)
select id
from t
group by id
having max(days)=5
order by id
不用寫sql就行。
你先刪除,然后右鍵表名,設(shè)計,把id列刪除掉,保存,然后再右鍵,設(shè)計,添加一個id列,然后設(shè)置成自增id就行了。
前提是,你之前的id沒有跟其他表有什么關(guān)聯(lián),否則就弄錯了。對應不上。
網(wǎng)頁名稱:sqlserver連續(xù),sql判斷連續(xù)
本文URL:http://chinadenli.net/article18/dsgjcdp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、手機網(wǎng)站建設(shè)、企業(yè)網(wǎng)站制作、關(guān)鍵詞優(yōu)化、品牌網(wǎng)站制作、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)