Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6211677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:22:48+00:00 2026-05-24T06:22:48+00:00

Trying to find the best way to write this SQL statement. I have a

  • 0

Trying to find the best way to write this SQL statement.

I have a customer table that has the internal credit score of that customer. Then i have another table with definitions of that credit score. I would like to join these tables together, but the second table doesn’t have any way to link it easily.

The score of the customer is an integer between 1-999, and the definition table has these columns:

Score
Description

And these rows:

60   LOW
99   MED
999  HIGH

So basically if a customer has a score between 1 and 60 they are low, 61-99 they are med, and 100-999 they are high.

I can’t really INNER JOIN these, because it would only join them IF the score was 60, 99, or 999, and that would exclude anyone else with those scores.

I don’t want to do a case statement with the static numbers, because our scores may change in the future and I don’t want to have to update my initial query when/if they do. I also cannot create any tables or functions to do this- I need to create a SQL statement to do it for me.

EDIT:

A coworker said this would work, but its a little crazy. I’m thinking there has to be a better way:

SELECT 
  internal_credit_score
  (
    SELECT
      credit_score_short_desc
    FROM
      cf_internal_credit_score
    WHERE
      internal_credit_score = (
                                SELECT 
                                  max(credit.internal_credit_score) 
                                FROM 
                                  cf_internal_credit_score credit  
                                WHERE 
                                  cs.internal_credit_score <= credit.internal_credit_score
                                  AND credit.internal_credit_score <= (
                                                                        SELECT
                                                                          min(credit2.internal_credit_score)
                                                                        FROM
                                                                          cf_internal_credit_score credit2
                                                                        WHERE
                                                                          cs.internal_credit_score <= credit2.internal_credit_score
                                                                      )
                              )
  )
FROM 
  customer_statements cs
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:22:49+00:00Added an answer on May 24, 2026 at 6:22 am

    You can use analytic functions to convert the data in your score description table to ranges (I assume that you meant that 100-999 should map to ‘HIGH’, not 99-999).

    SQL> ed
    Wrote file afiedt.buf
    
      1  with x as (
      2    select 60 score, 'Low' description from dual union all
      3    select 99, 'Med' from dual union all
      4    select 999, 'High' from dual
      5  )
      6  select description,
      7         nvl(lag(score) over (order by score),0) + 1 low_range,
      8         score high_range
      9*   from x
    SQL> /
    
    DESC  LOW_RANGE HIGH_RANGE
    ---- ---------- ----------
    Low           1         60
    Med          61         99
    High        100        999
    

    You can then join this to your CUSTOMER table with something like

    SELECT c.*, 
           sd.*
      FROM customer c,
           (select description,
                   nvl(lag(score) over (order by score),0) + 1 low_range,
                   score high_range
              from score_description) sd
     WHERE c.credit_score BETWEEN sd.low_range AND sd.high_range
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been searching online for awhile, trying to find the best way to
Im trying to find best practices to write PHP. I just wonder is this
I'm trying to find the best way to speed up the delivery of the
i am trying to find the best way to display results on my page
I am trying to find the best way to design the database in order
I'm currently trying to find the best way (in term of usability and performance)
Writing my first Linq application, and I'm trying to find the best way to
I'm trying to find out the most efficient (best performance) way to check date
I have an interesting query to do and am trying to find the best
I'm new to Oracle analytic functions and I'm trying to find the best way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.