我正在举办一场比赛,其中列出了学校老师观看的所有视频,但是如果他们观看的其中一个视频是一个词干,那就是'视频,我希望他们的名字被列出两次,以便他们可以两次进入绘图
基本上我在那里有一个case when
条款,这样如果一个视频中包含“' stem'在标题中,我的表格的最后一栏是“干”'别的' 0'。在最后一栏说干的情况下,我想重复整行。我希望这是有道理的。这是我到目前为止所拥有的;
SELECT *
FROM (
SELECT District,
SchoolName,
PersonnelId,
Name,
EmailAddress,
BeganViewingDate,
CASE WHEN SecondsCompleted >= SeventyFivePercent
THEN ContentName
ELSE '0' END as 'ContentName',
SegmentLengthInSeconds,
SecondsCompleted,
CASE WHEN contentname LIKE '%Stem%'
THEN 'Stem'
ELSE '0' END As 'Stem'
FROM (
SELECT vp.PersonnelId,
cp.EmailAddress,
CONCAT(cp.LastName, ', ', cp.FirstName) as Name,
vp.BeganViewingDate,
vp.SecondsCompleted,
c.ContentId,
c.ContentName,
c.SegmentLengthInSeconds,
ROUND(SegmentLengthInSeconds*0.75) as SeventyFivePercent,
cv.SchoolName,
cv.District
FROM PD360v2.ViewingProgress as vp
JOIN PD360v2.Content as c on vp.ContentId = c.ContentId
JOIN PD360v2.ClientPersonnel as cp on vp.PersonnelId = cp.PersonnelId
JOIN PD360v2.ClientView as cv on cp.ClientId = cv.Id
WHERE vp.BeganViewingDate BETWEEN '2016-02-02 08:00:00' AND '2016-02-09 07:59:00'
AND cv.NcesDistrictId IN (List Of districts here)
) as a
ORDER BY PersonnelId) as b
WHERE ContentName not like 0
ORDER BY District, SchoolName, Name;
答案 0 :(得分:0)
我只是简要介绍一下sql,你应该添加自己想要的列
Select vp.name,'0' from PD360v2.ViewingProgress as vp
Where vp.BeganViewingDate between '2016-02-02 08:00:00' and '2016-02-09 07:59:00' And cv.NcesDistrictId in (List Of districts here)
Union all
Select vp.name,'Stem' from PD360v2.ViewingProgress as vp
join PD360v2.Content as c on vp.contentid=c.contentid
Where vp.BeganViewingDate between '2016-02-02 08:00:00' and '2016-02-09 07:59:00' And cv.NcesDistrictId in (List Of districts here) and contentname like '%Stem%'