Pulling the latest record when there are multiple records with different dates in Oracle HCM - oracle-sqldeveloper

I am written a query which pulls work schedule data on person level in Oracle Fusion HCM. What is the filter or the join condition which I need to add to pull the latest date column.
I have used the tables
PER_SCHEDULE_ASSIGNMENTS PSA
, ZMM_SR_SCHEDULES_TL ZSST
, PER_ALL_ASSIGNMENTS_M PAAM
, PER_ALL_PEOPLE_F PAPF
The query returns 4 rows with different dates. How to return only 1 row which has the latest date column in it?

Use SYSDATE BETWEEN EFFECTIVE_START_DATE AND EFFECTIVE_END_DATE in all the tables where the date start date is there.
This will get you the current row as of today from those tables. You won't have any duplicates anymore.

Related

Query to get Last month's Data in DB2

I need to fetch last 2 months data in DB2 environment ,What is the query? The dates are changing ,so ,it must be dynamic.
If you want to get latest dates which are dynamically inserted then do something like below
select * from ur_table where urdate between (select max(urdate)- 2 months from urtable) and (select max(urdate) from urtable)

Searching for max date dynamically

I have the need to compare a date column with the max(date column) while making a filter selection.
E.g., when I compare [Date] = {max([Date])}, it finds the max/latest date in the entire data and compares. This gives me correct result when the latest month is included in the filter, but fails if I keep all months except the latest.
Is there a way in which the latest date can be searched in the subset of the data (based on filter selection)?
I am working with Redshift database (live connection).
look at the attached. https://www.dropbox.com/s/5zdkw9n003rxgvl/170524%20stack%20question.twbx?dl=0
{fixed : max(date)} will reflect only what is in the context filter.

Newbie to HQL - Date conversions in Hive - extract Year from free flow text varchar100

I have a simple HQL statement which works. I want to be able to count the occurrence's by Year or by Month. The data Quality is not good,and the incorporationdate column is held as a varchar100 and contains free flowing text and nulls
So I cannot use Substring or YEAR as I need to only perform a extract on the format mm/dd/yyyy to pull out the Year or month. Ideally I would like to create a View and create 2 new Columns , one to show the year and one to show the month this would be the perfect scenario.
select
incorporationdate, count(incorporationdate) from default.chjp2
group by companynumber,incorporationdate
===================================================
Regards
JP
you could use if and test any condition you want before using substring:
select if(date is not null and date rlike '^\d{2}\/\d{2}\/\d{4}$', substr(7),null)

PostgreSQL 8.2 extract week number from a a date field

This might be a simple one but I haven't got a solution yet. I have a create_date field which is a date type, and a revenue number. I want to see weekly break down of revenue.
I can get the numbers easily in tableau because of built in functionality but doing it in PostgreSQL is where I need some help.
If you want the revenue by week, you'll need to group and aggregate:
select extract (week from create_date) as week, sum(revenue) from table group by week

How to get all rows from last inserted date in a table?

So, if I do an insert everyday, how do I get the latest rows of data that correspond to the latest date from Postgresql using SQlAlchemy?
Do this with two queries. First get the latest date. Then get the rows with that date. Here's an example where the Item model has an updated date column.
latest = session.query(func.max(Item.updated)).scalar()
items = session.query(Item).filter_by(updated=latest).all()