sql按时间取去重最近_sql server 窗口函数去重和MOSS数据库获取

select *

from(

SELECT ROW_NUMBER() over (partition by a.cameraip,a.carPlate order by a.cameraip,a.intime) num,*

FROM [Camera].[dbo].[truck_Gate] a with(nolock)

where intime>‘2019-02-27‘

)a

where a.num = 1

order by a.cameraip,a.intime

按摄像头类型,时间来去掉重复

//MOSS数据获取考勤sql

with t1 as (

select

case when cast(tp_ContentTypeId as int)=-135314910 then N‘出差培训‘

when cast(tp_ContentTypeId as int)=-339275661 then tp_ColumnSet.value(N‘data(/nvarchar6)[1]‘, ‘nvarchar(30)‘)

when cast(tp_ContentTypeId as int)=1808594290 then N‘加班‘

when cast(tp_ContentTypeId as int) =-888033353 then N‘补休‘

else N‘值班‘

end type1 ,

b.tp_Title,[tp_Created] ,CONVERT(varchar(10), [tp_Created], 23) as 日期,tp_ColumnSet

, SUBSTRING(tp_ColumnSet.value(‘data(/datetime1)[1]‘, ‘varchar(30)‘),0,11) as 日期1,

tp_ColumnSet.value(N‘data(/nvarchar6)[1]‘, ‘nvarchar(30)‘) as 假期

from WSS_Content_80_XXJS.[dbo].[AllUserData] a left join [WSS_Content_80_XXJS].[dbo].[UserInfo] b on a.tp_Author=b.tp_ID

where

[tp_ListId]=‘4516AEC6-1278-4A7D-BC46-521A1F112F7A‘ and dateadd(HOUR,8,[tp_Created]) >‘2019-06-01‘

and dateadd(HOUR,8,[tp_Created])

--and tp_Author in(57,376)

)

select b.empcname,b.attrulename,b.schdate,t1.type1 from [AS0801_OnLine].[dbo].[V_SchResultInfoAll] b

left join t1 on t1.tp_Title=b.empcname collate Chinese_PRC_90_CI_AI and t1.日期1=b.schdate collate Chinese_PRC_90_CI_AI

where b.schdate>‘2019-06-01‘ and b.schdate

原文:https://www.cnblogs.com/mlwork/p/11528733.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值