goodmm 发表于 2018-10-4 13:52:49

mySql变量应用示例

-- 1.自定义一个时间变量并设置为当前日期的前一天  SET @startTime = CONCAT(date_sub(curdate(),interval 1 day),'%');
  -- 也可以从这里手动指定日期
  -- SET @startTime = '2017-04-13%';
  -- 显示要查询的日期
  -- select@startTime;
  select REPLACE(@startTime,'%','') as 日期,当日活跃用户,当日新增用户 from
  (
  -- 2.查询当日活跃用户

  select '01' as>  select DISTINCT uname from app_loginLog where logindate like @startTime
  ) as t
  ) as a,
  -- 3.查询当日新增用户

  (select '01' as>  where a.id = b.id;

页: [1]
查看完整版本: mySql变量应用示例