条件查询结果

时间:2018-06-07 09:14:44

标签: sql oracle

这里有一个问题的简化。 我有下表:

trigger

我想编写一个查询let data = { "0": { "trigger": 17 }, "1": { "trigger": 3 }, "2": { "trigger": 40 }, "3": { "trigger": 4 }, "4": { "trigger": 19 }, "5": { "trigger": 70 }, "6": { "trigger": 80 }, "7": { "trigger": 0 }, "8": { "trigger": 0 }, "9": { "trigger": 5 }, "10": { "trigger": 4 } } let arrVal = []; for (var keys in data) { arrVal.push(data[keys].trigger) }; console.log(arrVal)的查询,如果是,则在 ad hoc 创建的列中返回Student_table +-----------+--------------------+---------------------+ | Student | Graduation_date | First_working_date | +-----------+--------------------+---------------------+ | John | 12/10/2013 | 15/03/2015 | | Alan | 22/05/2014 | 12/04/2014 | | Lucy | 14/03/2014 | 14/03/2014 | +-----------+--------------------+---------------------+ 值。

这样的事情:

Graduation_date is <= First_working_date

有这样的结果

True

我在Oracle DB(12g)上使用Sql。

3 个答案:

答案 0 :(得分:1)

在SQL中使用以下CASE-WHEN-ELSE expression

SELECT student, 
   ( CASE WHEN Graduation_date <= First_working_date THEN 'TRUE'
          ELSE 'FALSE'
          END ) AS Early_Worker
   FROM student_table;

STUDENT EARLY_WORKER
------- ------------
 John   TRUE
 Alan   FALSE
 Lucy   TRUE

SQL Fiddle Demo

答案 1 :(得分:1)

这是查询:

SELECT Student,(CASE WHEN Graduation_date <= First_working_date 
THEN
 'TRUE' ELSE 'FALSE' END) AS Early_Worker
from student_table

答案 2 :(得分:1)

您可以尝试使用此方法:

SELECT Student,
CASE WHEN(Graduation_date <= First_working_date) THEN 'True'
ELSE 'False' END AS Early_worker
FROM student_table