by selecting the most recent decisiondate for a client, not all dates...

Hello

Consider the following situation:
I have 4 tables:


PD_CLIENT
CLIENT_ID
RNR
.. more data .the customer...

PD_LINKCLIENTCOMPOSITION
COMPOSITION_ID
CLIENT_ID
LEVEL_ID

PD_COMPOSITIONLEVEL
LEVEL_ID
LEVEL
S_TYPE

PD_LINKCLIENTDECISION
DECISION_ID
DATE_DECISION
CLIENT_ID


Some info with these tables
There are the customers
Customers have a composition one or several compositions have levels and these compositionlevels have different types
For customers, the decisions are made on a certain date. Sometimes it is possible to have more than one decision of a customer.

(the actual database is much larger than that, but I left out that we don't need to my question)

I need is:_
ALL customers, who have a composition with the leveltype "IGO", as well as the date of their most recent decision between 2 dates given. (if they do not have a decision yet, I do not need them in the results)

I wrote this query:
SELECT PD_CLIENT.CLIENT_ID, TO_CHAR(PD_LINKCLIENTDECISION.DATE_DECISION, 'DD-MM-YYYY') DATE_DECISION 
FROM PD_CLIENT , PD_LINKCLIENTCOMPOSITION , PD_COMPOSITIONLEVEL, PD_LINKCLIENTDECISION 
WHERE PD_CLIENT.CLIENT_ID = PD_LINKCLIENTCOMPOSITION.CLIENT_ID 
AND PD_LINKCLIENTCOMPOSITION.COMPOSITION_ID = PD_COMPOSITIONLEVEL.NIVEAU_ID 
AND PD_CLIENT.CLIENT_ID = PD_LINKCLIENTDECISION.CLIENT_ID
AND PD_COMPOSITIONLEVEL.S_TYPE = 'IGO' 
AND PD_LINKCLIENTDECISION.DATE_DECISION >= TO_DATE('01-01-2011', 'DD-MM-YYYY') 
AND PD_LINKCLIENTDECISION.DATE_DECISION <= TO_DATE('31-12-2011', 'DD-MM-YYYY') 
ORDER BY PD_CLIENT.RNR ASC
This ALMOST gives me what I need. now it gives me the client_id, gives with ALL dates of decision between 2 dates. I only need the newest one. Can someone help me change that? It is probably something small. I thought I knew how to solve, but I continue to not now, I have not any more close to the result with this query :)

Published by: 901981 on 16-dec-2011 05:46

How about some analytics?
Try something like:

not tested

select client_id
,      date_decision
from (
      SELECT PD_CLIENT.CLIENT_ID,
             TO_CHAR(PD_LINKCLIENTDECISION.DATE_DECISION, 'DD-MM-YYYY') DATE_DECISION,
             row_number() over (partition by PD_CLIENT.CLIENT_ID order by PD_LINKCLIENTDECISION.DATE_DECISION desc ) rn
        FROM PD_CLIENT,
             PD_LINKCLIENTCOMPOSITION,
             PD_COMPOSITIONLEVEL,
             PD_LINKCLIENTDECISION
       WHERE PD_CLIENT.CLIENT_ID = PD_LINKCLIENTCOMPOSITION.CLIENT_ID
         AND PD_LINKCLIENTCOMPOSITION.COMPOSITION_ID =
             PD_COMPOSITIONLEVEL.NIVEAU_ID
         AND PD_CLIENT.CLIENT_ID = PD_LINKCLIENTDECISION.CLIENT_ID
         AND PD_COMPOSITIONLEVEL.S_TYPE = 'IGO'
         AND PD_LINKCLIENTDECISION.DATE_DECISION >= TO_DATE('01-01-2011', 'DD-MM-YYYY')
         AND PD_LINKCLIENTDECISION.DATE_DECISION <= TO_DATE('31-12-2011', 'DD-MM-YYYY')
      )
where rn=1;  

Tags: Database

Similar Questions

  • I have 12 items. I just downloaded the most recent update. It will not open the RAW files from my Panasonic TZ70?

    I have 12 items. I just downloaded the most recent update. It will not open the RAW files from my Panasonic TZ70?

    See the faq for the compatibility of ACR:

    FAQ: Photoshop Elements will work with my camera, or why does not open my raw files?

    Your camera would need ACR version 9 which is not supported by 12 elements.

    You can:

    -upgrade to 13 items, with updates of version 13.1.1

    - or use the free DNGconverter mentionned in the links at the bottom of this faq. You'll be able set of entire folders to convert your raw files to DNG PSE12 can read and modify.

  • Select the most recent DATE for identification.

    Hi all

    I need to SELECT records with the most recent DATE for each code. A DATE range is part of the selection criteria.

    My data.
    MY_ID MY_DATE
    1684662 26 JANUARY 09
    1424097 27 JANUARY 09
    1684663 27 JANUARY 09
    1684664 27 JANUARY 09
    1684672 28 JANUARY 09
    0689073 28 JANUARY 09
    1052476 21 JANUARY 09
    1052476 21 JANUARY 09
    1360828 23 JANUARY 09
    1684661 23 JANUARY 09
    1052476 30 JANUARY 09
    1052476 30 JANUARY 09
    1052476 30 JANUARY 09
    1052476 30 JANUARY 09

    The code below works fine when you select 1 ID in the subselect, but with several ID he always selects rownum = 1 (of course). As far my mind takes me.
    SELECT my_id,
    my_date
    Of
    (SELECT my_id,
    my_date
    FROM my_table
    ORDER BY DESC my_date
    )
    WHERE rownum = 1
    AND * {color: #ff0000} my_id = 1052476 {color} *.
    AND TO_CHAR(my_date,'YYYY/MM/DD') BETWEEN ' 01 / 01/2009 ' AND '' 2009/01/31;

    If I could somehow pass the ID SELECT in the subselect WHERE clause I should have done this.

    Any suggestions?

    Thanks in advance for your help,

    Lou

    One of the many soultions possible.

    ME_XE?with data as
      2  (
      3     select 1684662 as id, to_date('26-JAN-09','dd-mon-yyyy') as the_date from dual union all
      4     select 1424097 as id, to_date('27-JAN-09','dd-mon-yyyy') as the_date from dual union all
      5     select 1684663 as id, to_date('27-JAN-09','dd-mon-yyyy') as the_date from dual union all
      6     select 1684664 as id, to_date('27-JAN-09','dd-mon-yyyy') as the_date from dual union all
      7     select 1684672 as id, to_date('28-JAN-09','dd-mon-yyyy') as the_date from dual union all
      8     select 0689073 as id, to_date('28-JAN-09','dd-mon-yyyy') as the_date from dual union all
      9     select 1052476 as id, to_date('21-JAN-09','dd-mon-yyyy') as the_date from dual union all
     10     select 1052476 as id, to_date('21-JAN-09','dd-mon-yyyy') as the_date from dual union all
     11     select 1360828 as id, to_date('23-JAN-09','dd-mon-yyyy') as the_date from dual union all
     12     select 1684661 as id, to_date('23-JAN-09','dd-mon-yyyy') as the_date from dual union all
     13     select 1052476 as id, to_date('30-JAN-09','dd-mon-yyyy') as the_date from dual union all
     14     select 1052476 as id, to_date('30-JAN-09','dd-mon-yyyy') as the_date from dual union all
     15     select 1052476 as id, to_date('30-JAN-09','dd-mon-yyyy') as the_date from dual union all
     16     select 1052476 as id, to_date('30-JAN-09','dd-mon-yyyy') as the_date from dual
     17  )
     18  select id, the_date
     19  from
     20  (
     21     select id, the_date, max(the_date) over (partition by id) as max_the_date
     22     from data
     23  )
     24  where the_date = max_the_date;
    
                    ID THE_DATE
    ------------------ --------------------------
                689073 28-JAN-0009 12 00:00
               1052476 30-JAN-0009 12 00:00
               1052476 30-JAN-0009 12 00:00
               1052476 30-JAN-0009 12 00:00
               1052476 30-JAN-0009 12 00:00
               1360828 23-JAN-0009 12 00:00
               1424097 27-JAN-0009 12 00:00
               1684661 23-JAN-0009 12 00:00
               1684662 26-JAN-0009 12 00:00
               1684663 27-JAN-0009 12 00:00
               1684664 27-JAN-0009 12 00:00
    
                    ID THE_DATE
    ------------------ --------------------------
               1684672 28-JAN-0009 12 00:00
    
    12 rows selected.
    
    Elapsed: 00:00:00.03
    
  • MY POP3 accounts receive emails with lack and truncated attached files. This started only after the most recent update for Thunderbird Version 38.1.0

    I recently started having truncated the attachments in the emails to my POP3 accounts. The first I noticed was on 27 July 2015.
    I'm running Thunderbird Version 38.1.0 on Windows on Windows 7 Home Premium service pack 1. After the test, I found that this happens on all POP3 accounts only. IMAP accounts do not work properly.
    A single file is usually truncated, if I send several files to get a complete file one truncated and more sent are missing completely.

    I wanted to send a bug report, but your system is unusable because it asks us to load the daily accumulation and essay on a new account, but the link to the daily version is going nowhere. But it's ok

    Thank you

    Thanks Matt.
    I had no luck by disabling addons, and I found that I'm unable to start in SafeMode (another problem to solve), but in research and the elimination of other culprits (malware) this problem stopped.

  • The most recent airport TC is compatible with all other routers?

    I have a relatively complex setup, in which case I have 2 TP-Link routers & outdoor CPE of TP-Link covering an acre & two buildings.  You want to have the capabilities of backup for my new MacBook.  The discussions I've seen so far are either old or do not seem to solve the problem...  Ideally, I replace the main router with TC and run ethernet to SCE in open air that feeds on 2nd router for the 2nd building.

    Routers are routers, and it is usually not much matter if they are wired... It is only when you use wireless configuration that things get complicated.

    A lot depends on how your existing two routers are connected... both should not be in router mode...

    There is no reason why you can not try to replace the main router with TC... test and see...

    If you experience problems after the exact problems... but first you need to know this modem and high-speed type are you?

  • Unable to connect after the most recent firmware for Microsoft Surface Pro 3 update

    Hi, I upgraded my Surface Pro to Windows 10 2... had no problems connecting to R7000 on band 5G. After upgrade the R7000 firmware to the latest version (V1.0.4.30_1.1.67), I now have problems connecting on the band of 5 G. Tablet must be adjacent to the router to connect on 5G band however once connected is connection is kept at distance (about 50 feet). However if I choose the 2.4GH I have no problem in establishing the initial connection to a distance of band. Did someone else has this problem and is there a solution?

    Thank you!

    Thanks a bunch, I went through all the processes of 'Factory Reset' and which certainly did not help. I took your advice and your instructions on return to 1.0.4.28 and it worked like a charm!

    I am now my Surface automatically compressed to a distance of 50 feet or more, through 3 walls on my terrace (as far as I dared so far) no problemo!

    With the latest firmware, I had to be sitting next to the router. The latest firmware is really baaad!

    Thank sagain for your help!

  • BlackBerry Curve 8320 Smartphone T-Mobile system the most recent version for 8GB media card?

    I want to install a 8 GB memory card in my T-Mobile 8320. Should what system I install so it can recognize the larger paper size?

    Thank you.

    BlackBerry Device Software media card size limit

    BlackBerry Device Software 4.2.0 - up to 2 GB

    BlackBerry Device Software 4.2.1 - up to 4 GB

    BlackBerry Device Software 4.2.2 - up to 4 GB

    BlackBerry Device Software 4.3.0 - up to 8 GB

    BlackBerry Device Software 4.5.0 - up to 8 GB

    BlackBerry Device Software 4.5.0.81 and above - up to 16 GB

    BlackBerry Device Software 4.6.0 - up to 32 GB

    http://www.BlackBerry.com/BTSC/search.do?cmd=displayKC&docType=kc&externalId=KB05461&sliceId=SAL_Pub...

  • The most recent data in a table view

    I'm adding values to a bulletin board as in the example, but I want to be the most recent data for the user to see the top line.

    He keeps adding to the bottom, and then the user will have to Diecut down see all data.      Can I select the most recent data somehow or get auto-scrolling data table are applied?     I tried registers to shift as well, but no luck.

    Here's my VI

    Thank you

    Mike

    Have you read the help of the function insert in the table? He clearly says that if you leave the unwired index entries, it will insert at the end. So, don't let the unwired index entries. Wire a '0' to the row index.

  • How to find the most recent record?

    How to find the most recent record?

    Hello

    It is part of our Bill the elements table, retrieved by the following query:

    SELECT movimento, dt_movimento, cd_material,
    cd_tp_operacao, nf, series,
    sole, pr_unitario
    Of itemfat
    WHERE cd_material IN ('722136', '759177', ' 810725', 818848')
    AND cd_tp_operacao ("' 1102 c ' ', ' 2102 C")
    ORDER BY cd_material,
    dt_movimento


    MOVIMENTO DT_MOVIMENTO CD_MATERIAL CD_TP_OPERACAO NF SERIES AS PR_UNITARIO
    2008-03-11 2137625, 722136 2102 1084738 3 120 2 915
    2588890 08/05/2008 722136-2102 1090987 3 120 2,5615
    755522 09/10/2007 759177-2102 101449 1 200 0.6
    701055 03/10/2007 810725-2102 1013865 1 36 10.9
    1588804 20/12/2007 810725 2102 1014182 1 96 10.9
    1305653 03/12/2007 818848-2102 108555 1 240 6.5
    3102134 07/18/2008 818848 2102 109784 1 360 6.5


    Seems that I whant to retrieve only the most recent records for each item, as:

    MOVIMENTO DT_MOVIMENTO CD_MATERIAL CD_TP_OPERACAO NF SERIES AS PR_UNITARIO
    2588890 08/05/2008 722136-2102 1090987 3 120 2,5615
    755522 09/10/2007 759177-2102 101449 1 200 0.6
    1588804 20/12/2007 810725 2102 1014182 1 96 10.9
    3102134 07/18/2008 818848 2102 109784 1 360 6.5


    Can someone help me with a sentece SQL to do?

    Thanks in advance.

    You can certainly do it:

    SELECT   movimento, dt_movimento, cd_material, cd_tp_operacao, nf, serie,
             quantidade, pr_unitario
        FROM itemfat i
       WHERE cd_material IN ('722136', '759177', '810725', '818848')
         AND cd_tp_operacao IN ('1102C', '2102C')
         AND dt_movimento =
                (SELECT MAX (dt_movimento)
                   FROM itemfat d
                  WHERE d.cd_material = i.cd_material
                    AND d.cd_material IN ('722136', '759177', '810725', '818848')
                    AND d.cd_tp_operacao IN ('1102C', '2102C'))
    ORDER BY cd_material, dt_movimento
    

    : p

  • selecting a field value, which is the most recent CREATE_DATE

    I have two fields in the table CREATE_DATE (Date) and QUEBEC (varchar). How the value of the field for record with the most recent CREATE_DATE? So, if the table contains the following records

    AS CREATE_DATE
    ABCD ON 20/12/2008
    2008-12-21 DEFH
    2009-01-10 ALINE

    I want to request to return ALINE. I now have a query "select table where rownum = 1 order by desc CREATE_DATE. Is there a better way to do it?

    Thank you
    Ravi

    Select from the table where CREATE_DATE = (SELECT MAX (CREATE_DATE) FROM table)

  • version the most recent upgrade of QuickWeb for dv6t-3000 CTO Notebook

    I need a link to get the latest version of HP quickWeb for my laptop dv6t-3000 CTO.

    Hello

    I believe that the following link is the most recent:

    FTP://ftp.HP.com/pub/SoftPaq/sp47001-47500/sp47192.exe

    or you can try:

    http://h10025.www1.HP.com/ewfrf/wc/softwareDownloadIndex?cc=us&LC=en&softwareitem=ob-101938-1

    Kind regards.

  • Update problem can remove them except for the most recent? Thank you!

    Hello!  In Control Panel, there are about 20 programs that all say the same thing.  They are updated for Windows and IE 8 security.  The only difference is the date, which date as far back as 2010.  Can I remove them except for the most recent?  Thank you!

    # They are all necessary.

  • I'm trying to download the media feature pack for windows 7n and it tell me to validate using GenuineCheck, but when I do it says that I should download the most recent version uses 64-bit window 7n

    I'm trying to download the media feature pack for windows 7n and it tell me to validate using GenuineCheck, but when I do it says that I should download the most recent version uses 64-bit window 7n

    You must use internet explore 32 bit.

  • Select / display of the most recent image.

    Hi, I use Bridge to see the photos I take captive.

    Is there a way to keep the most recent selected image so that I can see the most recent shot?

    OK I got it to work, but only with Bridge CS5 , he dislikes cs6 or cc.

    The code is here:- http://expirebox.com/download/abc4e20ea65c95853809a500fe92f105.html

    ExpireBox | BridgePreviewLatestFile.zip

    I used the film mode, and once a new file is droped in the folder displayed in the bridge.

    Bridge CS5 is always the best!

  • Hello, I've just updated my Photoshop for the most recent version, Im having problems with flow tool, is - that someone is having this problem too?

    Hello, I've just updated my Photoshop for the most recent version, Im having problems with flow tool, is - that someone is having this problem too?

    Hi tonyc75479545,

    Greetings.

    Please check this thread - Photoshop CC 2015.1 liquefy lightens the result on the 16-bit per channel images

    Concerning

    Rohit

Maybe you are looking for

  • Leer fichero datalogger dat

    Buenas tardes, espero that me podais help MI problema es el siguiente: Necesito UN leer a fichero .dat created by a data recorder, in el than canales are como el timestamp, canales humedad y canales of temperatura. Cuando intento tighter me salta one

  • hp4620: microsoft word doc file does not print

    Previous posted problem resolved with firmware update. I can't find now to cancel. I'm sorry. Attention, supervisor of the forum. I posted a problem just an hour ago or two. "Unable to communicate with the printer.  Now I can't cancel the request.

  • My screen resolution changed on its own

    I change user (Windows Vista Home Edition) when the resolution passes just by himself from 1920 x 1200 to 800 x 600.  1920 x 1200 is my largest resolution available and it has been defined for both users and works beautifully for over a year.  Now, w

  • Netflix/media center extender

    I use windows vista Home premium with media center.  I have a linksys dma2200 extender connected to the media center for viewing in another room.  I have a netflix account and am able to view on my PC, but cannot show via the media center extender. 

  • Problem with HARD drive, loss of disk space of 250 GB to 32, after recovering

    Hey guys, I have sucha a problem and I will be grateful for everyone who can help me. The thing is, that my computer actually windows (Vista Home Basic) has detected an error and after that stop, then automatic recovery system went itno action, but a