创建基于SQL的查看案例
我有一个由3列A,B,C的表格,
C列C最初是完全空的,对于每个条目A都有数字或B具有数字(从不在同一行中),
我想创建一个视图,该视图可为每个检查检查行如果a = x和b为null或0,则在col中写入a的值。
例子:
有人可以帮助我,我仍然是SQL的新手
I have a table of 3 columns A,B,C
initially column C is completely empty and for every entry either A has a number or B has a number (never both in the same row)
I want to create a view that checks for every row if A=x and B is null or 0 then write the value of A in col.
EXAMPLE:
Can someone help guide me, I am still new to sql
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用该视图,但是
更新
Thsi不会包括发生的情况。 0和b> 0由于您尚未指定要做的事情,因此此查询将始终在B之前进行A
You can'z use a VIEW for that but an
UPDATE
Thsi will not include what happens wehen A > 0 and B > 0 as you haven't specify what to do so this query will always take A before B
正如您提到的,让我们假设具有A,B和C列的表ABC,
并且您想根据值将C显示为A或B的值。
然后,您可以通过两种方法创建视图,以实现
否则,
如果要使用Col A/B的值更新C,则
Let's assume a table ABC with column A, B and C as you mentioned
And you want to display column C as value of either A or B based upon value
then you can create View by two methods to achieve the desired result
Or else,
If you want to update Column C with Value of col A/B then
尝试此视图。它阐明了您的要求。
在SQL中,编写语句是一个好主意,因此它们易于阅读和推理。
Try this view. It spells out your requirement.
It's a good idea in SQL to write statements so they're easy to read and reason about.