如何执行此查询以比较日期

时间:2017-06-18 13:32:11

标签: sql date

撰写查询以显示年龄超过Balakrishnan'的学生。根据升序order中的名字对结果进行排序。

输出应该如下所示

+--------+-----------+----------+-------------+------------+-----------+
| STUDID | FIRSTNAME | LASTNAME |   STREET    |    CITY    |    DOB    |
+--------+-----------+----------+-------------+------------+-----------+
|   3009 | Abdul     | Rahman   | HAL         | Bangalore  | 19-JAN-88 |
|   3002 | Anand     | Kumar    | Indiranagar | Bangalore  | 19-JAN-88 |
|   3001 | Dileep    | Kumar    | Jai Nagar   | Bangalore  | 10-MAR-89 |
|   3004 | Gowri     | Shankar  | Gandhipuram | Coimbatore | 22-DEC-87 |
|   3008 | John      | Dravid   | Mylapore    | Chennai    | 15-SEP-87 |
|   3006 | Prem      | Kumar    | Ramnagar    | Coimbatore | 17-MAY-87 |
|   3007 | Rahul     | Dravid   | KKNagar     | Chennai    | 08-OCT-87 |
+--------+-----------+----------+-------------+------------+-----------+

2 个答案:

答案 0 :(得分:0)

试试这个: - 它可能对你有帮助。

SELECT * FROM TABLE_NAME
WHERE DOB < TO_DATE('DOB_of_Balakrishnan','DD-MM-YYYY')
ORDER BY FIRSTNAME;

我正在使用oracle 11g。

答案 1 :(得分:0)

我看到没有提供Balakrishnan的DOB ...... 试着用这个:

SELECT *
FROM table_name
WHERE dob<(SELECT dob 
            FROM table_name
            WHERE LOWER(firstname)='bala')
ORDER BY firstname;