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 8915389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:57:58+00:00 2026-06-15T04:57:58+00:00

Question: How can I assign a code such as CC=1 and WP=2 and make

  • 0

Question: How can I assign a code such as CC=1 and WP=2 and make that part of the the query to get desired results? If there are multiple transactions on the same transaction date then apply the business rule.

Here’s my query on Oracle 11g

select tid, 
       cycle,
       apply_no, 
       seq_no, 
       trans_date, 
       trans_type,
       priority
from ( select tid, 
              cycle,
               apply_no, 
               seq_no, 
               trans_date, 
                trans_type,
                rank() over (partition by tid,
                                 order by trans_date desc,seq_no desc) priority
from transactions where tid=1              

Current Results

TID  cycle    apply_no  seq_no trans_date   trans_type  priority
----------------------------------------------------------------
1    201420    2        2       27-NOV-12   WP          1
1    201320    1        1       27-NOV-12   CC          2
1    201420    2        1       16-OCT-12   CC          3

Desired Results

TID  cycle     apply_no seq_no trans_date trans_type  priority
---------------------------------------------------------------
1    201420    2        2      27-NOV-12  CC          1
1    201320    1        1      27-NOV-12  WP          2
1    201420    2        1      16-OCT-12  CC          3

Reason: Business rules state CC takes priority over WP (not because CC sorts before WP)
if trans_date is same.

  • 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-06-15T04:57:59+00:00Added an answer on June 15, 2026 at 4:57 am

    Since your trans_type order is actually alphabetical, you could just add that to your order by in the rank function. However, to be more clear I would use a decode.. something like:

    with transactions as
    (
        select 1 tid, 201420 cycle, 2 apply_no, 2 seq_no, to_date('27-NOV-12','DD-MON-YY') trans_date, 'WP' trans_type from dual union all
        select 1 tid, 201320 cycle, 1 apply_no, 1 seq_no, to_date('27-NOV-12','DD-MON-YY') trans_date, 'CC' trans_type from dual union all
        select 1 tid, 201420 cycle, 2 apply_no, 1 seq_no, to_date('16-OCT-12','DD-MON-YY') trans_date, 'CC' trans_type from dual
    )
    select tid, 
           cycle,
           apply_no, 
           seq_no, 
           trans_date, 
           trans_type,
           priority
    from ( select tid, 
                  cycle,
                   apply_no, 
                   seq_no, 
                   trans_date, 
                    trans_type,
                    rank() over (partition by tid
                                     order by trans_date desc,decode(trans_type,'CC',1,'WP',2,3),seq_no desc) priority
    from transactions where tid=1 );
    

    Which produces:

           TID      CYCLE   APPLY_NO     SEQ_NO TRANS_DATE  TRANS_TYPE   PRIORITY
    ---------- ---------- ---------- ---------- ----------- ---------- ----------
             1     201320          1          1 27-NOV-2012 CC                  1
             1     201420          2          2 27-NOV-2012 WP                  2
             1     201420          2          1 16-OCT-2012 CC                  3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get make method in which I can assign values to multiple
There is a similar question How can I assign the result of a subroutine
My question is if we can assign/bind some value to a certain item and
Question Can I style just a part of a single character? Meaning CSS attributes
I have the following code that is working to assign a locale based first
This is going to be a very simple question, I have code that looks
My question can better be explained via example code. I am using POCO with
I have a question about this code: getContent: (index) -> content = @get('content') element
The entire original question was based on a mistake. You can NEVER assign the
Short Question: Can I specify wildcards for custom console folding? If so, what is

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.