1.定义变量
declare @startTime varchar(255)
-- 2.设置变量
set @startTime = convert(VARCHAR(10),dateadd(day,-1,getdate()),120)+'%'
-- 也可以从这里指定要查询的日期
-- set @startTime = '2017-04-05%'
-- 显示指定的日期
PRINT(@startTime)
select REPLACE(@startTime,'%','') as 日期,当日活跃用户,当日新增用户 from
(
-- 3.查询当日活跃用户
select '01' as id,count(1) as 当日活跃用户 from
(
select DISTINCT usId from loginLog t where CONVERT(varchar(100), t.addTime, 25) like @startTime
) as a
) as a2,
-- 4.查询当日新增用户
(select '01' as id,count(1) as 当日新增用户 from userT t where CONVERT(varchar(100), t.addTime, 25) like @startTime) b
where a2.id = b.id;
sqlServer变量运用示例
原创
©著作权归作者所有:来自51CTO博客作者清风凌雪的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Oceanbase为啥新入数据select慢
oceanbase运维,it小白,OB数据库
数据库 数据 MySQL Oceanbase