早教吧 育儿知识 作业答案 考试题库 百科 知识分享

sql语句看不懂,今天看了朋友写的一个sql语句,没看懂什么意思,还望高手把它翻译成通俗易懂的中文DELETEFROMResumeStatsWHEREYMD=CONVERT(varchar(8),@Yesterday,112);WITHDayResumeStatsAS(SELECTCONVERT(varchar

题目详情
sql语句看不懂,今天看了朋友写的一个sql语句,没看懂什么意思,还望高手把它翻译成通俗易懂的中文
DELETE FROM ResumeStats WHERE YMD=CONVERT(varchar(8), @Yesterday, 112);
WITH DayResumeStats AS(
SELECT CONVERT(varchar(8), @Yesterday, 112) AS YMD,
ISNULL(SUM(CASE WHEN Created BETWEEN @Yesterday AND @Today THEN 1 ELSE 0 END),0) AS NewResumes,
ISNULL(SUM(CASE WHEN Refreshed BETWEEN @Yesterday AND @Today THEN 1 ELSE 0 END),0) AS RefreshedResumes,
ISNULL(SUM(CASE WHEN OpenType<>0 THEN 1 ELSE 0 END),0) AS OpenResumes,
ISNULL(SUM(CASE WHEN (Rank<60 and Created BETWEEN @Yesterday AND @Today) THEN 1 ELSE 0 END),0) AS LowRankResumes
FROM Resumes
)
▼优质解答
答案和解析
这个应该是SQL2005以上版本的语句,且该语句用于临时用途;
with关键字从resume表生成一个CTE(用表表达式,仅作用于单个查询语句之内,可以认为是创建的命名临时表)DayResumeStats;该CTE中筛选出所有不符合条件的NewResumes,
RefreshedResumes,OpenResumes,和 LowRankResumes;(看字面是筛选出所有非新的、未更新的、未开放的和低级别的简历),
delete 语句从该DayResumeStats中删除所有YMD=@yesterday的记录;,