Help to calculate the difference between the set of dates

CASE_NAME         TEST_NAME           TEST_ON_HOLD_DATE        TEST_OFF_HOLD_DATE           Days On Hold (Not actual column in the table)

A   1           01-JAN-12               03-JAN-12          3 
A   2           01-JAN-12               05-JAN-12          5
A   3           01-JAN-12            08-JAN-12          8
A   4           04-JAN-12            10-JAN-12          7
A   5           13-JAN-12            16-JAN-12          4
                                                                                                                                            -----        
                                                                           27               I actually want  total hold days as 14

B  1             01-FEB-12            03-FEB-12          3
B  2           02-FEB-12            05-FEB-12          4
B  3           03-FEB-12            08-FEB-12          6
B  4           05-FEB-12            10-FEB-12          6
B  5           13-FEB-12            16-FEB-12          4
                                                                                                                                           -----
                                                                           23              Actual hold days for case B :14 days 

I am trying to calculate actual hold days for each case ,could some one please help me to give me idea to start he issue.



create table Caris_Life (case_name varchar2(10) ,Test_name varchar2 (10),Test_on_Hold_date date ,test_off_hold_date date);

insert into  Caris_life  (case_name,Test_name,Test_on_Hold_date,test_off_hold_date) values ('A',1,TO_DATE ('01/01/2012','MM/DD/YYYY'),TO_DATE ('01/03/2012','MM/DD/YYYY'));

insert into  Caris_life  (case_name,Test_name,Test_on_Hold_date,test_off_hold_date) values ('A',2,TO_DATE ('01/01/2012','MM/DD/YYYY'),TO_DATE ('01/05/2012','MM/DD/YYYY'));

Insert Into  Caris_Life  (Case_Name,Test_Name,Test_On_Hold_Date,Test_Off_Hold_Date) Values ('A',3,To_Date ('01/01/2012','MM/DD/YYYY'),To_Date ('01/08/2012','MM/DD/YYYY'));

insert into  Caris_life  (case_name,Test_name,Test_on_Hold_date,test_off_hold_date) values ('A',4,TO_DATE ('01/04/2012','MM/DD/YYYY'),TO_DATE ('01/10/2012','MM/DD/YYYY'));

insert into  Caris_life  (case_name,Test_name,Test_on_Hold_date,test_off_hold_date) values ('A',5,TO_DATE ('01/13/2012','MM/DD/YYYY'),TO_DATE ('01/16/2012','MM/DD/YYYY'));

insert into  Caris_life  (case_name,Test_name,Test_on_Hold_date,test_off_hold_date) values ('B',1,TO_DATE ('02/01/2012','MM/DD/YYYY'),TO_DATE ('02/03/2012','MM/DD/YYYY'));

insert into  Caris_life  (case_name,Test_name,Test_on_Hold_date,test_off_hold_date) values ('B',2,TO_DATE ('02/02/2012','MM/DD/YYYY'),TO_DATE ('02/05/2012','MM/DD/YYYY'));

Insert Into  Caris_Life  (Case_Name,Test_Name,Test_On_Hold_Date,Test_Off_Hold_Date) Values ('B',3,To_Date ('02/03/2012','MM/DD/YYYY'),To_Date ('02/08/2012','MM/DD/YYYY'));

insert into  Caris_life  (case_name,Test_name,Test_on_Hold_date,test_off_hold_date) values ('B',4,TO_DATE ('02/05/2012','MM/DD/YYYY'),TO_DATE ('02/10/2012','MM/DD/YYYY'));

insert into  Caris_life  (case_name,Test_name,Test_on_Hold_date,test_off_hold_date) values ('B',5,TO_DATE ('02/13/2012','MM/DD/YYYY'),TO_DATE ('02/16/2012','MM/DD/YYYY'));
Published by: vijayp on Sep 14, 2012 22:58

Published by: vijayp on Sep 14, 2012 23:09

>
Thank you very much for the idea, I will work with your query to see why he gives different number.
>
I think that I have now. Try this

with q as (
select case_name, test_name, test_on_hold_date, test_off_hold_date,
       lag(test_off_hold_date, 1, test_on_hold_date - 1) over (partition by case_name
        order by test_on_hold_date) prior_off_hold_date,
       lead(test_on_hold_date, 1, test_off_hold_date + 1) over (partition by case_name
        order by test_on_hold_date) next_on_hold_date
from Caris_life
),
   p as (
select q.*,
        case when (test_on_hold_date > prior_off_hold_date) -- if this record starts a new date range
          then test_off_hold_date - test_on_hold_date +1       -- then just subtract the dates
          when (test_off_hold_date > prior_off_hold_date)      -- but if this record overlaps the previous one
             then test_off_hold_date - prior_off_hold_date        -- then adjust this records off date to only count the new days
        else 0 end days
 from q
)
select case_name, sum(days) days_held from p group by case_name

CASE_NAME,DAYS_HELD
A,14
B,14

Tags: Database

Similar Questions

  • Use the data from a DataSet as a source for another (the join between the sets of data)

    Hello. I come with a problem, very simple, but which I think is not implemented in the beer Pub.

    In the DataModel, I create a DataSet, providing some data (for example, a string from a web service), and after this, I create another set of data that uses this string as a parameter for a database query. Is this possible? The only link I found between the sets of data is only this concatenation of the main data set.

    Is there a way that I can do? Thank you!

    * [url http://www.java-forums.org/blogs/advanced-java/collection/] Java collection *.

    In Publisher 10 g and sooner you can use a data model to the join and the structure of data from different sources SQL.

    In Publisher, 11g, you can join data sets for which Publisher can 'know' on the data fields. For example. In addition to SQL data sets, you can reach Excel, LDAP, MDX and answers. Web Services, like XML file are data sets that editor does not know the data fields, so unfortunately, no way to join them... I know.

    Also, true that LOVs can either be SQL or data fixed (i.e. the entered values).

    Allowing the Web Service as a source of LOV or a way to define data fields, it's something for us to consider for a future version.

    Mike

  • extend the set of data

    Hi all
    Please find the below example scenario where I have to extend the set of data.
    I working on oracle 10g and all by extending the data set, we should exclude weekends. The sample is only for 2 ID, but there may be more than one.
    Thanks for your help.
     
    
    ID                    ST_DT          END_DT          VAL 
    ====               ========         =======        ======== 
    1                  2/2/2011             2/4/2011       4 
    1                  2/4/2011             2/8/2011       5 
    1                  2/8/2011                            6 
    2                  1/28/2011           2/1/2011        2 
    2                  2/1/2011                            8 
    
    ID                    DT             VAL 
    ====                ========      =======        
    1                 2/2/2011           4 
    1                 2/3/2011           4 
    1                 2/4/2011           5 
    1                 2/7/2011           5 
    1                 2/8/2011           6 
    1                 2/9/2011           6 
    2                 1/28/2011          2 
    2                 1/31/2011          2 
    2                 2/1/2011           8 
    2                 2/2/2011           8 
    2                 2/3/2011           8 
    2                 2/4/2011           8 
    2                 2/7/2011           8 
    2                 2/8/2011           8 
    2                 2/9/2011           8 
    
    select 1 as id,to_date('02/02/2011','MM/DD/YYYY') as st_dt,to_date('02/04/2011','MM/DD/YYYY') as end_dt, 4 as val from dual 
    union all 
    select 1 as id,to_date('02/04/2011','MM/DD/YYYY') as st_dt,to_date('02/08/2011','MM/DD/YYYY') as end_dt, 5 as val from dual 
    union all 
    select 1 as id,to_date('02/08/2011','MM/DD/YYYY') as st_dt, null as end_dt, 6 as val from dual 
    union all 
    select 2 as id,to_date('01/28/2011','MM/DD/YYYY') as st_dt,to_date('02/01/2011','MM/DD/YYYY') as end_dt, 2 as val from dual 
    union all 
    select 2 as id,to_date('02/01/2011','MM/DD/YYYY') as st_dt,null as end_dt, 8 as val from dual; 

    Hello

    I guess, when end_dt is NULL, you want to use the current date as end_dt, and the results you have posted are the desired results if the query is executed on February 10, 2011.

    Here's one way:

    WITH     got_n_days     AS
    (
         SELECT     id, st_dt, end_dt, val
         ,     NVL ( end_dt
                  , TRUNC (SYSDATE)
                  ) - st_dt          AS n_days
         FROM     table_x
    --     WHERE     ...     -- If you need any filtering, put it here
    )
    ,     cntr          AS
    (
         SELECT     LEVEL  - 1     AS n
         FROM     (
                   SELECT  MAX (n_days)     AS max_n_days
                   FROM     got_n_days
              )
         CONNECT BY     LEVEL <= max_n_days - 1
    )
    SELECT       d.id
    ,       d.st_dt + c.n          AS dt
    ,       d.val
    FROM       got_n_days     d
    JOIN       cntr          c  ON     c.n     < d.n_days
    WHERE       TO_CHAR ( d.st_dt + c.n
                  , 'DY'
                , 'NLS_DATE_LANGUAGE=ENGLISH'     -- If necessary
                ) NOT IN ('SAT', 'SUN')
    ORDER BY  id
    ,            dt
    ;
    

    Basically, each line of your original table must be repeated n times, where n is the number of days between (included) st_dt and end_dt (not included). The first subquery calculates this number and the main query results by combining your data with a "counter table", NTRC, which contains a line for each value of n that you may need. This 'table' is generated in the second auxiliary request.
    The join produces a line for each day. The WHERE clause eliminates the Saturday and Sunday from these results.

    Thanks for posting the sample data in a useful form. That really helps.

    Published by: Frank Kulash, February 10, 2011 14:29

  • Need help to calculate the difference between times

    Hi all

    I have two fields that stores just the hour in 24-hour ex: 08:00 and 20:00 now I want to calculate the difference between two times

    Kindle help me

    Thanks for your help

    Thank you
    Ravi

    Hello

    diiference in hours

    SQL> WITH T AS (SELECT '08:00' ST_TIME, '20:00' END_TIME FROM DUAL)
      2  SELECT (TO_DATE (END_TIME, 'HH24:MI') - TO_DATE (ST_TIME, 'HH24:MI')) * 24 DIFF_HOURS
      3    FROM T;
    
    DIFF_HOURS
    ----------
            12
    
    SQL> 
    

    G.

  • Help!  Calculate a percentage between two fields that the sum of columns

    Members of the forum good day!

    I'm hoping to get help with and model RTF I use to sum up the output of a query in PeopleSoft.

    I have a line with two fields of the query and a third field calculates a percentage using the query fields:
    Row1, Field1: EXPR14_14
    Row1, Field2: EXPR1_1
    Row1, Field3: <? xdofx: If EXPR1_1 <>0 and EXPR14_14 0 then (EXPR1_1 DIV EXPR14_14) <>* 100 or 0 end if? >

    I have a second row who has these fields:
    Row2, Field1: <? sum (EXPR14_14)? >
    Row2, Field2: <? sum (EXPR1_1)? >
    Row3, Field3: I need the third field to calculate the percentage of sum of two fields.

    I tried different ways to insert this calculation with no luck. It's my first time to create a rtf report and any help would be gratly appreciated.

    In advanced thank you for your help.

    Kind regards
    Raquel

    For the calculation of percentage you can use something similar to this (adjust the formula you need)

    For Row1, Field3:

    Hope that helps. If you need more help, send me the xml file and the [email protected] model

    Thank you
    Bipuser

  • How can I justify the difference between varchar and varchar2 data type

    Hi all

    How can I justify the difference between the data type varchar and varchar2 on any table for space management.
    Is there any query to justify this.


    Concerning
    Girish

    Published by: boujemaa on February 2, 2011 21:23

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14220/datatype.htm#sthref3780


    The VARCHAR data type

    The VARCHAR data type is synonymous with the VARCHAR2 data type. To avoid any changes in behavior, always use the VARCHAR2 data type to store strings of variable length.

  • Need help to reset the setting SESSIONS

    Hi people,

    Environment: Oracle 10g Rel 2

    I'm trying to reduce the number of sessions to the database as follows

    * Wink # call existing values *.
    show parameters session;
    show parameters processes;
    show parameters transactions;
    
    sessions     integer  170
    processes    integer  150
    transactions integer  187
    * # Change the value of parameter SESSION *.
    alter system set sessions=3 scope=spfile;
    * # Bouncing the instance *.
    shutdown immediate; 
    * # Start the instance *.
    startup;
    * # Check if the new value takes effect *.
    show parameters session;
    
    Output: sessions integer     170
    * # Check if the new value is in spfile *.
    select NAME||','||VALUE||','||DISPLAY_VALUE||','||ISSPECIFIED
    from v$spparameter
    where NAME like 'session%'
    
    
    Output: sessions,3,3,TRUE
    * # Check if the database has been started with the spfile *.
    SELECT DECODE(value, NULL, 'PFILE', 'SPFILE') "Init File Type"
           FROM sys.v_$parameter WHERE name = 'spfile'
    
    
    Output: 
    
    Init F
    ------
    SPFILE
    Any ideas as to why the SESSIONS setting don't take effect?

    Thanks in advance

    rogers42

    Sessions setting is derived from the setting process, and in most cases, there should be no reason to set it and do not touch.

    Setting of 3 sessions is totally, absolutely stupid as background processes with sessions too.
    That could be another reason why Oracle happily choose to ignore your changes.

    You should spend more time to read the documents, in order to avoid further attempts to wreck Oracle and create more havoc.

    -----------------
    Sybrand Bakker
    Senior Oracle DBA

  • ETA App should help to get the time and date feature HELP!

    Hi everyone, I'm doing an application where I need to get the time and date of the antone device can help, I know there is a function such as getDate or getTime but im not to know how to use it.

    As far as I know,

    I use this to get the time system (it returns long type)

    System.currentTimeMillis();
    

    After that, you can use SimpleDateFormat to convert date and time

    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy, HH:mm");
    String time = sdf.format(new Date(System.currentTimeMilis()));
    
  • Unlike COUNTY and the difference in data between 2 sets of data

    Hey guys,.
    I have a question here, probably, it revolves around the UNION, INSERSECT and LESS and maybe something else I'm missing.

    I'm two sets of questions, and I have 2 paintings.
    select count(student_id) from adhoc_student_table1;
    select count(student_id) from adhoc_student_table2;
    
    select student_id from adhoc_student_table1 order by student_id;
    select student_id from adhoc_student_table2 order by student_id;
    These tables contain data and have been sorted by student_id. I want to find the difference in NUMBER between the first set of SELECT and I want to find a difference in the student ID in the second set to SELECT.

    Any ideas? As always, any help is appreciated!

    Hello

    These tables do contain data and have been sorted by student_id. I want to find the difference in COUNT between the first set of SELECT and I want to find a difference in Student IDs in the second set of SELECT.
    

    Hope this helps

    select (select count(student_id) from adhoc_student_table1) -
       (select count(student_id) from adhoc_student_table2) from dual
    
    ---If you want the difference in first table not available in second table.
    
    select student_id from adhoc_student_table1 order by student_id
    minus
    select student_id from adhoc_student_table2 order by student_id
    
    -- or you wanted the difference from both table.
    with tab1 as
    (
       select student_id from
          adhoc_student_table1
    )
    tab2 as
    (
        select student_id from
    adhoc_student_table2
    )
    select * from (select student_id from tab1
                         union select student_id from tab2)
    minus
    select * from (select student_id from tab1
                        intersect select student_id from tab2)
    )
    

    If you could post the input samples and expected, maybe you can get a more valuable solution.

    Concerning
    Anurag Tibrewal.

  • How can I ignore the differences between databases when reading data from a database?

    My boss wants me to create a text parser that analyzes the sentence below and executes a SQL query.

    "' get the table field1, field2, field3,..., Manyfield [where to SQL conditional statements].

    This corresponds to "select Field1, Field2, field3,..., table Manyfield where blahblah".

    Since different DBMS have different timestamp formats, this sentence should be changed for each DBMS.

    Ignore the differences is to do anlayzer that converts a certain type of timestamp string to one that adapts to each DBMS complex a text.

    But it seems ridiculous to adopt this solution when there might be an elegant solution.

    LabVIEW Toolkit of DB is not able to hide the differences.

    Does anyone have a better idea that I do?

    I remember having a problem like this when you are working with an older version of an Oracle server. I was able to change the session by setting the 'NLS_TIMESTAMP_FORMAT '.

    This page might be of interest; I found this, when searching for "NLS_TIMESTAMP_FORMAT".

    Database portability: Date and Timestamp columns

    (PS String Format and channel Scan functions work well with the correct date format specifiers. See the link below in my signature for the ISO 8601 timestamp/string conversions)

  • Need help to change the setting of the function key in Windows 8, help?

    Hey, I bought a HP laptop yesterday (which I am very satisfied) and decided to play Guild Wars 2 and all of my favorite PC games. In the game, I discovered that all of the F buttons work without pressing FN, which is annoying. So although I am tyring to combat various things I'll always turn down the brightness and turn off the wireless so if I could know how to swap it around, so when I press FN I can turn down brightness etc that would mean I could now use the F buttons normally any help would be nice thank YOU!

    Hello

    You should be able to change this setting in your Bios menu - see the document at the following link.

    http://support.HP.com/us-en/document/c02035108

    Kind regards

    DP - K

  • Can someone help me with the set up for skydrive file sharing?

    In my photo app I am developing the home section. He told me to right click on SkyDrive in the bar tasks, select settings and check "Allow me to share all files with this pc" is turned on. It is, but when I try and access the photos app hosting I still get the same message. Can someone help me set this or tell me if I do something wrong?

    Sharing of the checkbox in the settings of SkyDrive is not related to the photos somehow app.

    Sharing checkbox in the settings of SkyDrive, it's what allows you to go to another computer (such as your office or library) and then go to skydrive.com to access the files on your computer.

  • Need help to calculate the start and end time and place the result in a term like text box

    I did a search on the forum for calculating start and end time and found the code depending on which I am using as a formcalc on the duration field.
    ==============================================================
    Form1. Page1.duration::calculate - (FormCalc, client)

    If (HasValue (StartTime) and HasValue (EndTime)) then
    industrial var = Time2Num (StartTime.formattedValue, "h: mm A")
    var = Time2Num out_ (EndTime.formattedValue, "h: mm A")
    If (IN2 > = out_) then
    xfa.host.messageBox ("start time cannot be greater than or equal to the end time.")
    $.rawValue = null
    on the other
    var out_ - IN2 = diff
    $.rawValue = diff/3600000
    endif
    on the other
    $.rawValue = null
    endif
    =============================================================

    Then, when I enter for example from 15:30, an hour of beginning and end of 04:00

    The duration field will say 0.5

    How can I get my form to say 30 minutes instead of placing a decimal?

    Secondly, how can I use field models LC where the employee can just type 330 or 03:30 and it automatically based on the computer's clock on time to start 15:30?

    Any help will be greatly appreciated.  Thank you.

    Attached is the form for display:

    https://Acrobat.com/#d=f1kxh5qjuow5ujyZduF8OQ

    To view the results in a regular time format, you can use:

    $.rawValue = Num2Time (diff/3600000, "HH: mm")

    For a flexible time entry check this example.

    http://thelivecycle.blogspot.com/2011/05/flexible-Eingabe-von-Daten-und-Zeiten.html

  • Need help to calculate the delta value

    Can someone help me with this please?

    I have a table source as:
     
     device        index     value                     time 
        a              1         15               2009-07-07 12:00:00
        a              1         20               2009-07-07 13:00:00
        a              1         25               2009-07-07 14:00:00
        a              1         30               2009-07-07 15:00:00
    
        a              2         10               2009-07-07 12:00:00
        a              2         20               2009-07-07 13:00:00
        a              2         30               2009-07-07 14:00:00
        a              2         35               2009-07-07 15:00:00
    
        a              3         30               2009-07-07 13:00:00
        a              3         40               2009-07-07 15:00:00
    And looks at the final table, I need to generate
     
     device        index     value                     time 
        a              1         5               2009-07-07 13:00:00
        a              1         5               2009-07-07 14:00:00
        a              1         5               2009-07-07 15:00:00
    
        a              2         10             2009-07-07 13:00:00
        a              2         10             2009-07-07 14:00:00
        a              2         5               2009-07-07 15:00:00
    
        a              3         30             2009-07-07 13:00:00
        a              3         0               2009-07-07 14:00:00
        a              3         40             2009-07-07 15:00:00
    Thanks a lot for your help!

    Looks like you need to fill in some gaps.

    You can use a join partitioned to fill the gaps, then use the analytic funcitons. For more information about partitioned joins, see [http://download.oracle.com/docs/cd/B19306_01/server.102/b14223/analysis.htm#sthref1836].

    Here's my original query with a medium update query (t2 - t3 now)

    with t1 as (select 'a' device, 1 IND, 15 "VALUE", to_date('2009-07-07 12:00:00','rrrr-mm-dd hh24:mi:ss') "TIME" from dual
      union all select 'a', 1, 20, to_date('2009-07-07 13:00:00','rrrr-mm-dd hh24:mi:ss') from dual
      union all select 'a', 1, 25, to_date('2009-07-07 14:00:00','rrrr-mm-dd hh24:mi:ss') from dual
      union all select 'a', 1, 30, to_date('2009-07-07 15:00:00','rrrr-mm-dd hh24:mi:ss') from dual
      union all select 'a', 2, 10, to_date('2009-07-07 12:00:00','rrrr-mm-dd hh24:mi:ss') from dual
      union all select 'a', 2, 20, to_date('2009-07-07 13:00:00','rrrr-mm-dd hh24:mi:ss') from dual
      union all select 'a', 2, 30, to_date('2009-07-07 14:00:00','rrrr-mm-dd hh24:mi:ss') from dual
      union all select 'a', 2, 35, to_date('2009-07-07 15:00:00','rrrr-mm-dd hh24:mi:ss') from dual
      union all select 'a', 3, 30, to_date('2009-07-07 13:00:00','rrrr-mm-dd hh24:mi:ss') from dual
      union all select 'a', 3, 40, to_date('2009-07-07 15:00:00','rrrr-mm-dd hh24:mi:ss') from dual
    ), t3 as (
    select t1.device
         , t1.ind
         , nvl(t1.value,lag(nvl(t1.value,0)) over (partition by t1.device, t1.ind order by t2.time))
           - lag(nvl(t1.value,0)) over (partition by t1.device, t1.ind order by t2.time) "VALUE"
         , t2.time
      from t1
      PARTITION by ( t1.device, t1.ind)
      right join (select distinct time from t1) t2
        on t1.time = t2.time
    )
    select * from t3 where value is not null
    
    DEVICE IND                    VALUE                  TIME
    ------ ---------------------- ---------------------- -------------------------
    a      1                      5                      07-JUL-2009 13:00:00
    a      1                      5                      07-JUL-2009 14:00:00
    a      1                      5                      07-JUL-2009 15:00:00
    a      2                      10                     07-JUL-2009 13:00:00
    a      2                      10                     07-JUL-2009 14:00:00
    a      2                      5                      07-JUL-2009 15:00:00
    a      3                      30                     07-JUL-2009 13:00:00
    a      3                      0                      07-JUL-2009 14:00:00
    a      3                      40                     07-JUL-2009 15:00:00      
    
    9 rows selected
    

    Note: I had to finegle the first half NVL function to the value expression for the result is 0 instead of-30. If you want it to be - 30 place just change this function nvl to nvl(t1.value,0) instead.

    Published by: Sentinel July 8, 2009 16:40

  • SQL query for the set of data rows not values

    Hello!

    I use Oracle 10 g (10.2.0.1.0) and I need help to solve this difficult task. I have a huge table with more than 145000 records and I shows you only a sample of it:

    ID TEAMNAME_EN DT TEAMNAME_EN HPROB AM APROB FT
    324813 31/8 / 2012 DEN HAAG GRONINGEN 1.90 3.30 3.10 2
    324823 31/8 / 2012 MAINZ GREUTHER FÜRTH 1.75 3.25 3.65 2
    324805 31/8 / 2012 GAZELEC DIJON 1.60 3.15 4.75 1
    324810 31/8 / 2012 ÖREBRO DJURGÅRDEN 2.80 3.25 2 2.05
    324795 31/8 / 2012 FC KÖLN COTTBUS 1.85 3.20 3.35 2
    324837 31/8 / 2012 PORTLAND WOOD COLORADO RAPIDS 2,00 3.20 2.95 1
    324828 31/8 / 2012 DROGHEDA UNITED, DUNDALK 1.45 3.65 5.25 1
    324827 31/8 / 2012 CORK CITY SHAMROCK ROVERS 3,30 3,80 1.70 2
    324833 31/8 / 2012 BARUERI ASA 2.45 3.20 1-2.30
    324798 31/8 / 2012 GENÇLERBIRLIGI ORDUSPOR'A 2.00 3,10 X 3.00
    324814 31/8 / 2012 ALMERE CITY FC OSS 1,80 3,50 3,20 2
    324830 31/8 / 2012 CRICIÚMA BRAGANTINO 1.25 4.35 1 8.00
    324820 31/8 / 2012 VOLENDAM FC EINDHOVEN 1.80 3.25 3.45 1
    324818 31/8 / 2012 MVV MAASTRICHT TELSTAR 1.40 4.00 X 5.25
    324819 31/8 / 2012 DORDRECHT VEENDAM 1.80 3.25 3.45 1
    324834 31/8 / 2012 CEARÁ GUARATINGUETÁ 1.40 3.85 X 5.50

    If this table consists of
    dates
    teams (hometeam, awayteam)
    numbers for homewin, shoot, awaywin probability
    and the final result as 1, X, 2

    What I want is a sql query that returns to me for each hometeam, awayteam and (if possible in a single line)
    all documents of the hometeam which had the same number of prior probability. For example:
    CEARÁ (last line), I would like to the sql to show me all the records of CEARA who had _1.40 3.85 or 5.50_ in each of the three issues of probability, BUT the problem is that I do want separate lines... I can do so far is to calculate a sum of House probability, probability of drawing, close probability for each team but the same records are calculated again in each game of probability!

    This means if CEARÁ has 1.40-3.85-5.50 in the past it will return me this line only once, and not 3 times (one for each set of probability)

    I hope that I've done my duty,
    Thank you for your time and lights
    N. Saridakis

    Is that what you are looking for:

    select hometeam,
           awayteam,
           hw,
           hd,
           hl
    from  (select hometeam,
                  awayteam,
                  ft,
                  SUM(CASE ft
                      WHEN '1' THEN 1
                      ELSE 0
                      END) OVER (PARTITION BY hometeam) hw,
                  SUM(CASE ft
                      WHEN 'X' THEN 1
                      ELSE 0
                      END) OVER (PARTITION BY hometeam) hd,
                  SUM(CASE ft
                      WHEN '2' THEN 1
                      ELSE 0
                      END) OVER (PARTITION BY hometeam) hl
           from   plays)
    where ft is null
    

Maybe you are looking for

  • Dongle wireless Duo 13 - What is the security key?

    Hello VAIO Duo 13: When I plug the USB dongle and insert an ethernet cable, a new wireless access point is available. When I try to connect to it, Windows asks the security key. Anyone know what it is? (If I hold the button on the dongle, Windows tri

  • can not install the software for all in one photosmart 2610xi of disc of windows 7 pc

    I can't install the software for all in one photosmart 2610xi of disc of windows 7 pc.  Goes so far then stops and says cannot use the command "run as".  I am the administrator and logged as such.  I would like to use the software provided with to se

  • WRT 54GL - internet issue.

    I have router WRT-54GL almost 10 months and it works very well until one day... The description of the problem: I have a connection between -Laptop and the router (wireless) -PC and router (cable) When I start my laptop, I have a wireless connection

  • replacing hard drive for Pav P7-1240 &amp; SSD

    Part 1: I have a desktop computer Pavilion P7-1240. It is just 1.5 years... 1 TB Hitachi hard drive has not now.  I went out and bought a WD 1 TB Caviar Black internal Performance Desktop retail hard drive Kit (WD1003FZEX); go mainly for the guarante

  • OfficeJet 6700 Premium only print blank pages

    My Officejet 6700 Premium printer is only printing blank pages. I just replaced all the cartridges with HP new ones. The printer is now going through the motions but does not print blank pages. This happens for all what I am trying to print including