-- 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 id,count(1) as 當日活躍用戶 from ( select DISTINCT uname from app_loginLog where logindate like @startTime ) as t ) as a, -- 3.查詢當日新增用戶 (select '01' as id,count(1) as 當日新增用戶 from app_user where registerdate like @startTime) b where a.id = b.id;