Oracle query and aggregate function

前端 未结 2 1099
余生分开走
余生分开走 2021-01-26 11:31

I have table name employee_1 suppose in oracle. If the mobile_no and sim_no is same i want select maximum start_date. I have tried , but no success. Please help The employee_1 t

相关标签:
2条回答
  • 2021-01-26 12:08

    NOTE: Your definition, example data and expected result are not consistent. See that you include in the result the line:

    1111111111  1111111112  11/10/2017 21:02:44 13/10/2017 21:02:44
    

    where the Mobile and SIM numbers are different.

    Still, try this:

    EDIT: TOP 1 was replaced with LIMIT 1 (Oracle).

    SELECT LIMIT 1 Mobine_No , Sim_No , Start_Date , End_Date
      FROM YourTable
     WHERE Mobine_No = Sim_No 
    ORDER BY Start_Date DESC ;
    

    Alternative:

    SELECT Mobine_No , Sim_No , MAX(Start_Date) , End_Date
      FROM YourTable
    
    0 讨论(0)
  • 2021-01-26 12:20

    Try this, hopefully, it fulfills your requirement.

    select mobile_no,sim_no,start_date,end_date from(
    select mobile_no,sim_no,start_date,end_date,rank() over(partition by mobile_no,sim_no order by start_date desc) rn from employee_1)s
    where rn=1
    
    0 讨论(0)
提交回复
热议问题