我有一个数据库表有四列名为"Courses(CourseID,CourseName,CreditHours,LabSession)"
,我想编写SQL语句来检索Course表中的所有数据,此外,如果LabSession列中的SQL必须重复行(记录) row具有值"Y"
,否则将按原样检索行而不重复。
BTW,我正在使用Microsoft SQL Server数据库
答案 0 :(得分:2)
select CourseID,CourseName,CreditHours,LabSession from Courses
union ALL
select CourseID,CourseName,CreditHours,LabSession from Courses where LabSession='Y'
order by CourseID
答案 1 :(得分:2)
SELECT CourseID, CourseName, CreditHours, LabSession
FROM Courses
UNION ALL
SELECT CourseID, CourseName, CreditHours, LabSession
FROM Courses
WHERE LabSession = 'Y'
ORDER BY CourseId