Sql获取时间

def search_createtime_case_sql(mobile):
# 昨日 今日 上周 本周 上个月 -- 本月 去年 本年 过去7天 过去30天
sql_val = []
sql_val.append(
f"SELECT count(*) as num from t_case where doctorid = (select userGUID from t_dx_user where mobile = '{mobile}') and DataStatus = 1 and DATEDIFF(createtime,NOW())=-1 ")
sql_val.append(
f"SELECT count(*) as num from t_case where doctorid = (select userGUID from t_dx_user where mobile = '{mobile}') and DataStatus = 1 and DATEDIFF(updatetime,NOW())=0")
sql_val.append(
f"SELECT count(*) as num from t_case where doctorid = (select userGUID from t_dx_user where mobile = '{mobile}') and DataStatus = 1 and YEARWEEK(date_format(createtime,'%Y-%m-%d'),1) = YEARWEEK(now(),1)-1")
sql_val.append(
f"SELECT count(*) as num from t_case where doctorid = (select userGUID from t_dx_user where mobile = '{mobile}') and DataStatus = 1 and YEARWEEK(date_format(createtime,'%Y-%m-%d'),1) = YEARWEEK(now(),1)")
sql_val.append(
f"SELECT count(*) as num from t_case where doctorid = (select userGUID from t_dx_user where mobile = '{mobile}') and DataStatus = 1 and date_format(createtime,'%Y-%m')=date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),'%Y-%m')")
sql_val.append(
f"SELECT count(*) as num from t_case where doctorid = (select userGUID from t_dx_user where mobile = '{mobile}') and DataStatus = 1 and date_format(createtime,'%Y-%m')=date_format(now(),'%Y-%m')")
sql_val.append(
f"SELECT count(*) as num from t_case where doctorid = (select userGUID from t_dx_user where mobile = '{mobile}') and DataStatus = 1 and year(createtime)=year(date_sub(now(),interval 1 year))")
sql_val.append(
f"SELECT count(*) as num from t_case where doctorid = (select userGUID from t_dx_user where mobile = '{mobile}') and DataStatus = 1 and YEAR(createtime)=YEAR(NOW())")
sql_val.append(
f"SELECT count(*) as num from t_case where doctorid = (select userGUID from t_dx_user where mobile = '{mobile}') and DataStatus = 1 and DATEDIFF(createtime,NOW())<0 AND DATEDIFF(createtime,NOW())>-7")
sql_val.append(
f"SELECT count(*) as num from t_case where doctorid = (select userGUID from t_dx_user where mobile = '{mobile}') and DataStatus = 1 and DATEDIFF(createtime,NOW())<0 AND DATEDIFF(createtime,NOW())>-30")
return sql_val
posted on 2020-08-06 16:01  小王同学呀  阅读(115)  评论(0编辑  收藏  举报