英文:
Update select statement result in a column conditioned by another column (Oracle SQL)
问题
我正在尝试在Oracle SQL中编写一个Select查询,如果last_name列为空(不管first_name列中的值是什么),则将first_name列返回为空。对于第一行,“John”应返回为空,因为他没有last_name。我不想更新表,我只想要一个Select查询,如果last_name为空,就返回空的first_name。提前感谢!!!
这应该是结果。
英文:
I'm trying to write a Select query in Oracle SQL that will return first_name column as empty if last_name column is empty(Regarless what's in the first_name column value).
For the first row "John" should be return as empty since he has no last_name
I don't want to update the table, I just want a Select query that return empty first_name if last_name is empty. Thanks in advance!!!
答案1
得分: 1
你可以使用 CASE
表达式:
SELECT customer_id,
CASE
WHEN last_name IS NULL
THEN NULL
ELSE first_name
END AS first_name,
last_name,
age,
country
FROM table_name
英文:
You can use CASE
expression:
SELECT customer_id,
CASE
WHEN last_name IS NULL
THEN NULL
ELSE first_name
END AS first_name.
last_name.
age,
country
FROM table_name
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论