×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Effective Date Year < Year in a Different Table but Year is based on the 1st 3 Chars in String, e

Effective Date Year < Year in a Different Table but Year is based on the 1st 3 Chars in String, e

Effective Date Year < Year in a Different Table but Year is based on the 1st 3 Chars in String, e

(OP)
Are the results needed toward the bottom of this post, even possible? I hope I've explained it so it makes sense.

TABLES:

MAIN TABLE

ID TITLE EFFECTIVE_DATE (This is in the table as string and not date)
1 Placement Testing 10/01/2015
1 Testing 10/01/2014
1 Test 10/01/2012


JOIN TABLE

ID TERM (1st character is for 2000 and characters in position 2 and 3 is the year)
1 1175 (2017)
1 1145 (2014)
1 1135 (2013)

Result Needed (I only want the MAIN TABLE's last effective date year title < JOIN TABLE'S term year)

ID TERM TITLE
1 1175 (2017) Placement Testing - 2015 is the MAIN TABLE's last effective date year < 1175 (2017)
1 1145 (2014) Test - 2012 is the MAIN TABLE's last effective date year < 1145 (2014)
1 1135 (2013) Test - 2012 is the MAIN TABLE's last effective date year < 1135 (2013)

Any help is greatly appreciated!

RE: Effective Date Year < Year in a Different Table but Year is based on the 1st 3 Chars in String, e

The character string of year can be calculated as:
SELECT '20' || SUBSTR(JoinTable.TERM, 2, 2) FROM JoinTable;
The character string should be converted using TO_DATE for date range calculations.


==================================
advanced cognitive capabilities and other marketing buzzwords explained with sarcastic simplicity


RE: Effective Date Year < Year in a Different Table but Year is based on the 1st 3 Chars in String, e

SELECT A.Id, MAX(TO_DATE(A.Effective_date, 'MM/DD/YYYY'))
FROM Join_table B, Main_table A
WHERE A.Id = B.Id
AND TO_DATE(A.Effective_date, 'MM/DD/YYYY')
< TO_DATE('01/01/20' || SUBSTR(B.Term,2,2),'MM/DD/YYYY')
GROUP BY A.Id

Bill
Lead Application Developer
New York State, USA

RE: Effective Date Year < Year in a Different Table but Year is based on the 1st 3 Chars in String, e

(OP)
Hi Bill,

It works great if I don't have the TITLE as a field. When I add it then I get the error "ORA-00979: not a GROUP BY expression."

Thanks for your help!

RE: Effective Date Year < Year in a Different Table but Year is based on the 1st 3 Chars in String, e

Show your Select statement with the "TITLE as a field".
Did you add it to the SELECT and the GROUP BY part of your statement?


---- Andy

There is a great need for a sarcasm font.

RE: Effective Date Year < Year in a Different Table but Year is based on the 1st 3 Chars in String, e

Adding the title is easy, just add it to the group by



CODE

SELECT A.Id,a.Title MAX(TO_DATE(A.Effective_date, 'MM/DD/YYYY'))
FROM Join_table B, Main_table A
WHERE A.Id = B.Id
AND TO_DATE(A.Effective_date, 'MM/DD/YYYY')
< TO_DATE('01/01/20' || SUBSTR(B.Term,2,2),'MM/DD/YYYY')
GROUP BY A.Id,a.Title; 

When you are using aggregates in your select like MAX, MIN, SUM, AVG,... any items from the select that are not aggregated must be in a group by.

Bill
Lead Application Developer
New York State, USA

RE: Effective Date Year < Year in a Different Table but Year is based on the 1st 3 Chars in String, e

(OP)
When I don't have Title as a field and in the GROUP BY

ID Term Effective_Date(Year)
1 1175 2015
1 1145 2012
1 1135 2012

When I add Title as field and GROUP BY

ID Term Effective_Date(Year) Title
1 1175 2015  Placement Testing (I just want this title in effective date's year 2015 since 2015 is just prior to the year in this Term year 2017)
1 1175 2014 Testing
1 1175 2012 Test

1 1145 2012 Test

1 1135 2012 Test

Thanks for everyone's help. I really appreciate it!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close