简体   繁体   中英

How can we implement First() function used in Informatica in SQL?

I have an aggregate transformation in Informatica where Description1 column=First(Description). I want to implement the same in SQL query.Can anyone suggest how to do this? Sample Dataset Table name-ABC

Name               Expression
ID                 ID
DESCRIPTION 
DESCRIPTION1       FIRST(DESCRIPTION1)
INSERT_DATE 
INSERT_DATE1       FIRST(INSERT_DATE)
RANK    
RANK1              FIRST(RANK)

Please use below query,

select max(Description1) from Router_Transform;

If you are using sorter transformation in your Mapping, please use order by clause,

    select max(Description1) from Router_Transform order by column_name;

If you want the row with the smallest id , then you can sort the resultset and retain just one row. In standard SQL, you would typically use a row-limiting clause for this:

select t.*
from mytable
order by id
fetch first row only

Note that all databases support this syntax (but almost all have alternatives for that).

On the other hand, if you want to add more columns to each row that display the "first" value for each column, then you would use window function first_value() :

select
    t.*,
    first_value(description) over(order by id) description1,
    first_value(insert_date) over(order by id) insert_date1,
    first_value(rank)        over(order by id) rank1
from mytable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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