① 某一个字段表示一天,怎么用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 ,是否需要加“=”号了。 供你参考,看是否可帮到你。