使用多个 where 子句选择多个值 [英] Selecting multiple values with multiple where clauses

查看:67
本文介绍了使用多个 where 子句选择多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据 SQL 中的多个 where 子句选择多个列值.我做不到.

I want to select multiple column values based on multiple where clauses in SQL. I am not able to do it.

我正在尝试类似的东西

select c.fname,r.fname from customer as c LEFT JOIN retailer as r ON
r.customer_id = c.id where c.id > 10 OR r.id < 50.

基本上我希望我的 where 子句被一个一个执行,第一个输出(当 'where c.id>10' 被执行时)应该作为 c.fname 和第二个输出(当 'where r.id<50') 在一个 sql 查询中.

Basically I want both my where clauses to get executed one by one and first output(when 'where c.id>10' is executed) should come as c.fname and second output (when 'where r.id<50') in one sql query.

能做到吗?请帮忙.

推荐答案

尝试以下查询:

SELECT
c.fname,
r.fname
CASE WHEN r.id < 50 THEN 'output 1'             
     WHEN c.id > 10 THEN 'output 2' END AS 'OUTPUT_COLUMN'
FROM customer as c 
LEFT JOIN retailer as r 
ON r.customer_id = c.id

这篇关于使用多个 where 子句选择多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆