简体   繁体   English

oracle sql 在同一查询中过滤

[英]oracle sql filter in same query

I have a join_table as follows for a single person with id = 123.对于 id = 123 的单个人,我有一个 join_table 如下。

join_time加入时间

id  subject join_date
123 MATH    03-MAY-19
123 MATH    12-MAR-15
123 CS      05-JUN-12
123 CS      24-JUL-12
123 CS      27-JUN-14
123 HIST    18-AUG-14
123 HIST    19-DEC-12
123 SCI     20-MAY-02
123 SCI     26-JUL-93

My oracle sql output should be 1 per subject with the latest joining date and also the subject should be formatted as below:我的 oracle sql output 应该是每个主题 1 和最新加入日期,主题的格式也应该如下:

id  subject                 join_date
123 Maths                   03-MAY-19
123 Computer Science        27-JUN-14
123 History                 18-AUG-14
123 Science                 20-MAY-02

suggestions pls?建议?

Seems you need aggregation function and group by似乎你需要聚合 function 和 group by

    select id, subject, max(join_date)
    from my_table 
    group by id, subject

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM