使用 case when 语句创建视图
请参阅下面的示例,以便更清楚地了解我在做什么。
示例:
Create View v AS
Select T.*, S.Name, Case When T.TESTDATE = S.STUDYDATE
Then 'Yes' else 'No' END AS TakenTest
From Test T, Student S
Where T.TESTPAPERID = '12345'
And T.StudentNo = S.StudentNo;
创建视图成功。但是,它使用相同的值填充重复的行,例如:
TESTPAPERID StudentNo Name TakenTest
12345 6437 John Yes
12345 6437 John No
我如何解决它,因为我已经定义了 if T.TESTDATE = S.STUDYDATE then show yes。否则不行。并且不填充相同的值。
谢谢
Please refer to my example below for clearer understanding of what i'm doing.
Example:
Create View v AS
Select T.*, S.Name, Case When T.TESTDATE = S.STUDYDATE
Then 'Yes' else 'No' END AS TakenTest
From Test T, Student S
Where T.TESTPAPERID = '12345'
And T.StudentNo = S.StudentNo;
It create the view successfully. However, it populate duplicate rows with same values like:
TESTPAPERID StudentNo Name TakenTest
12345 6437 John Yes
12345 6437 John No
How can i resolve it as i already define that if T.TESTDATE = S.STUDYDATE then show yes. Otherwise no. And not populating the same values out.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果只有一行,请使用:
另外,这部分的编码很差:
因为它与以下内容相同:
To have only one row, use this:
Also, this part is poorly coded:
because it is IDENTICAL to: