① 某一個欄位表示一天,怎麼用sql取連續三天
select begin_dt
from (select begin_dt, count(*) over(partition by ch) cnt
from (select begin_dt,
to_date(begin_dt, 'yyyy-mm-dd') - row_number() over(order by begin_dt) ch
from liur_account)
)
where cnt >= 3;
② 誰有sql查詢語句的題目
1,求公司連續3天遲到的員工。遲到時間(要麼全部是早上三次,要麼全面是下午三次)。
2,一個超市每天都有營業額。
列出每天的營業額和截止到每天的總營業額。(比如,第一天 營業額 10 總營業額 10,第二天 營業額20 總營業額 30;第二天 營業額 10 總營業額 40);
3,刪除表中的重復數據只保留一行。表中沒有Id欄位.
4,求數據的第2頁。每頁10條數據。(幾種寫法);
5,查詢某一個資料庫中的所有表的欄位名字,欄位類型,欄位大小。
6,查詢公司年齡和小a相同,興趣和小a相同,但是薪水比小a低的男同事。
③ sql 查詢 連續幾天不登錄人員
select*from(selectdistinctc.)awheredateadd(day,-3,getdate())>(.account=b.accountorderbyb.loginTimedesc)
tableName為同一個表名
④ SQL查詢日期為連續的數據
/*求連續曠工三天以上的數據*/
declare @t table(name varchar(10), [date] datetime,n int default(1))
insert into @t(name,date) select '張三','2011.09.01'
union select '張三','2011.09.08'
union select '張三','2011.09.09'
union select '張三','2011.09.10'
union select '李四','2011.09.06'
union select '李四','2011.09.09'
union select '李四','2011.09.12'
union select '李四','2011.09.15'
union select '小五','2011.08.06'
select * from @t
--select name,COUNT(*) 次數
-- from @t group by name having(COUNT(*)>3)
declare @nm varchar(10),@d datetime,@n int=1,@lastNm varchar(10)='',@lastD datetime='1900.01.01',@lastN int =1
declare cur cursor for select name ,[date],n from @t order by name,date
open cur
fetch next from cur into @nm,@d,@n
while (@@FETCH_STATUS =0 ) begin
if @lastNm =@nm and @d=@lastD+1 begin
update @t set n = @lastN +1 where name=@nm and [date]=@d
select @lastN = n from @t where name=@nm and [date]=@d
set @lastNm=@nm
set @lastD =@d
end
else begin
set @lastNm = @nm
set @lastD =@d
set @lastN = @n
end
fetch next from cur into @nm,@d,@n
end
close cur
deallocate cur
select * from @t where n>=3
⑤ 如何查出連續三天不打卡的人員清單
試試: select * from employe where iccardid not in (select iccardid from 考勤表 where iotime > 開始時間 and iotime <開始時間+3) 由於時間欄位在查詢的時候,是相對麻煩的,你自己測試一下: iotime>=開始時間 iotime<=開始時間+3 ,是否需要加「=」號了。 供你參考,看是否可幫到你。