Query: group of data

Hello every one,
I have data as under, and tried to get solution
WITH te AS(SELECT 1 ID,0 ct,'123 main' st FROM dual
             UNION ALL
             SELECT 1 ID,1 ct,'123 main' st FROM dual
             UNION ALL
             SELECT 1 ID,0 ct,'123 main' st FROM dual
             UNION ALL
             SELECT 1 ID,0 ct,'124 main' st FROM dual
             UNION ALL
             SELECT 1 ID,0 ct,'124 main' st FROM dual
             UNION ALL
             SELECT 2 ID,0 ct,'3 main' st FROM dual
             UNION ALL
             SELECT 2 ID,0 ct,'3 main' st FROM dual
             UNION ALL
             SELECT 2 ID,0 ct,'65 main' st FROM dual
             UNION ALL
             SELECT 2 ID,0 ct,'65 main' st FROM dual
             UNION ALL
             SELECT 2 ID,0 ct,'65 main' st FROM dual
             UNION ALL
             SELECT 3 ID,0 ct,'99 st' st FROM dual
             UNION ALL
             SELECT 3 ID,1 ct,'99 st' st FROM dual
             UNION ALL
             SELECT 3 ID,1 ct,'888 st' st FROM dual
             UNION ALL
             SELECT 3 ID,1 ct,'888 st' st FROM dual
             UNION ALL
             SELECT 4 ID,1 ct,'222 west' st FROM dual
             UNION ALL
             SELECT 5 ID,0 ct,'555 east' st FROM dual
(SELECT *
   FROM (SELECT x.*,
                COUNT (x.ct) OVER (PARTITION BY x.ID, st ORDER BY x.ID,
                 x.st) ct1,
                COUNT (CASE
                         WHEN x.ct = 0 THEN ct
                       END) OVER (PARTITION BY x.ID, st ORDER BY x.ID,
                 x.st) ct2,
                COUNT (CASE
                         WHEN x.ct = 1 THEN x.ct
                       END) OVER (PARTITION BY x.ID, x.st ORDER BY x.ID,
                 x.st) ct3
           FROM te x))I would like to find
Following data from dataset as it is group on id and st for which one group of st has at least one ct=1 and other group on st has none ct=1 for one ID 1,
ID     CT     ST     CT1     CT2     CT3
1     0     123 main     3     2     1
1     1     123 main     3     2     1
1     0     123 main     3     2     1
1     0     124 main     2     2     0
1     0     124 main     2     2     0
4     1     222 west     1     0     1Thank you

WITH te AS(SELECT 1 ID,0 ct,'123 main' st FROM dual
             UNION ALL
             SELECT 1 ID,1 ct,'123 main' st FROM dual
             UNION ALL
             SELECT 1 ID,0 ct,'123 main' st FROM dual
             UNION ALL
             SELECT 1 ID,0 ct,'124 main' st FROM dual
             UNION ALL
             SELECT 1 ID,0 ct,'124 main' st FROM dual
             UNION ALL
             SELECT 2 ID,0 ct,'3 main' st FROM dual
             UNION ALL
             SELECT 2 ID,0 ct,'3 main' st FROM dual
             UNION ALL
             SELECT 2 ID,0 ct,'65 main' st FROM dual
             UNION ALL
             SELECT 2 ID,0 ct,'65 main' st FROM dual
             UNION ALL
             SELECT 2 ID,0 ct,'65 main' st FROM dual
             UNION ALL
             SELECT 3 ID,0 ct,'99 st' st FROM dual
             UNION ALL
             SELECT 3 ID,1 ct,'99 st' st FROM dual
             UNION ALL
             SELECT 3 ID,1 ct,'888 st' st FROM dual
             UNION ALL
             SELECT 3 ID,1 ct,'888 st' st FROM dual
             UNION ALL
             SELECT 4 ID,1 ct,'222 west' st FROM dual
             UNION ALL
             SELECT 5 ID,0 ct,'555 east' st FROM dual
select min(ID) ID,max (CT) CT, tab.ST,max(ct1) ct1,max(ct2) ct2,max(ct3) ct3  from (SELECT *
   FROM (SELECT x.*,
                COUNT (x.ct) OVER (PARTITION BY x.ID, st ORDER BY x.ID,
                 x.st) ct1,
                COUNT (CASE
                         WHEN x.ct = 0 THEN ct
                       END) OVER (PARTITION BY x.ID, st ORDER BY x.ID,
                 x.st) ct2,
                COUNT (CASE
                         WHEN x.ct = 1 THEN x.ct
                       END) OVER (PARTITION BY x.ID, x.st ORDER BY x.ID,
                 x.st) ct3
           FROM te x)) TAB
group by tab.ST
having ( sum(CT) > 0)ID     CT     ST     CT1     CT2     CT3
3     1     99 st     2     1     1
3     1     888 st     2     0     2
4     1     222 west     1     0     1
1     1     123 main     3     2     1

Similar Messages

  • TSQL query to calculate Count / Sum grouping by date on a Pivot Table

    Hi All
    I need help to group the pivot table output to group by dates and sum/count the values. I have a table like shown below.
    Date
    Student 
    Subject
    Hunt
    Marks
    18/02/2014
    Sam 
    Maths
    1
    20
    18/02/2014
    Sam 
    Maths
    1
    10
    18/02/2014
    Sam 
    Maths
    2
    30
    18/02/2014
    Luke
    Science
    1
    50
    17/02/2014
    Sam 
    Maths
    2
    50
    17/02/2014
    Luke
    Science
    2
    60
    16/02/2014
    Luke
    Science
    2
    20
    16/02/2014
    Luke
    Science
    3
    20
    I want to Group by dates and move the Hunt to columns calculating their counts and sum their marks too. Like given below.
    I wrote a pivot query like below but If i group it with dates and calculate the total marks it throws aggregate errors.
    Create Table Student_Log ([Date] datetime ,Student varchar (20), Subject varchar (20) ,Hunt int ,Marks int )
    Go
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Sam ','Maths','1','20')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Sam ','Maths','1','10')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Sam ','Maths','2','30')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Luke','Science','1','50')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-17 15:00:00.000','Sam ','Maths','2','50')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-17 15:00:00.000','Luke','Science','2','60')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-16 15:00:00.000','Luke','Science','2','20')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-16 15:00:00.000','Luke','Science','3','20')
    Go
    select * from Student_Log
    select [DATE] , [Student], [Subject] ,[1],[2],[3],[4],Total =([1]+[2]+[3]+[4])
    from
    ( select [Date], [Student], [Subject],[Hunt],[Marks] from Student_Log
    )x
    pivot
    count ( [Hunt]) for [Hunt]
    in ([1],[2],[3],[4])
    )p
    order by [Date] desc
    I have done this far only. More than this I need to enhance it with the Percentage of Hunts for each Student.
    ie like below table.
    On 18th Sam in Maths he had 2 rows on 1st hunt  and 1 row on 2nd hunt. So On the Pivot table is it possible to represent it on percentage using the Total Attempts column.
    Thanks a lot in advance.
    Its runnung in SQL 2000 Server.

    Create Table Student_Log ([Date] datetime ,Student varchar (20), Subject varchar (20) ,Hunt int ,Marks int )
    Go
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Sam ','Maths','1','20')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Sam ','Maths','1','10')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Sam ','Maths','2','30')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Luke','Science','1','50')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-17 15:00:00.000','Sam ','Maths','2','50')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-17 15:00:00.000','Luke','Science','2','60')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-16 15:00:00.000','Luke','Science','2','20')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-16 15:00:00.000','Luke','Science','3','20')
    Go
    select * from Student_Log
    ;with mycte as
    Select [Date], [Student], [Subject] ,
    Count(CASE WHEN [Hunt]=1 Then Hunt End) as Hunt1,
    Count(CASE WHEN [Hunt]=2 Then Hunt End) as Hunt2,
    Count(CASE WHEN [Hunt]=3 Then Hunt End) as Hunt3,
    Count(CASE WHEN [Hunt]=4 Then Hunt End) as Hunt4,
    Count(CASE WHEN [Hunt]=1 Then Hunt End)
    +Count(CASE WHEN [Hunt]=2 Then Hunt End)
    +Count(CASE WHEN [Hunt]=3 Then Hunt End)+
    +Count(CASE WHEN [Hunt]=4 Then Hunt End) as Total,
    ISNULL(SUM(CASE WHEN [Hunt]=1 Then Marks End),0) as Mark1,
    ISNULL(SUM(CASE WHEN [Hunt]=2 Then Marks End),0) as Mark2,
    ISNULL(SUM(CASE WHEN [Hunt]=3 Then Marks End),0) as Mark3,
    ISNULL(SUM(CASE WHEN [Hunt]=4 Then Marks End),0) as Mark4
    from Student_Log
    Group By [Date], [Student], [Subject]
    Select [Date], [Student], [Subject]
    , Cast(Hunt1*1./Total*100 as int) as [1]
    , Cast(Hunt2*1./Total*100 as int) as [2]
    ,Cast(Hunt3*1./Total*100 as int) as [3]
    ,Cast(Hunt4*1./Total*100 as int) as [4]
    ,Total,Marks=( Mark1+Mark2+Mark3+Mark4)
    from mycte
    order by [Date] DESC, Student desc
    drop table Student_Log

  • BAM Data Control - Group query with Active Data Service

    Trying to get a group query from a BAM data control to work with Active Data Service in an ADF application (JDeveloper 11.1.1.4.0).
    With a flat query, as the data changes, I can see DataChangeEvents fired, resulting in a data push to the client -
    <BAMDataChangeEventFilter> <log>
    #### DataChangeEvent #### on [DataControl name=CEP_Person_DOB_Flat, binding=data.view_mainPageDef.FlatDOB1.view_pageDefs_FlatDOBViewPageDef_WEB_INF_FlatDOB_xml_FlatDOB.QueryIterator]
    Filter/Collection Id : 1966
    Collection Level : 0
    Event Id : 5
    ==== DataChangeEntry (#1)
    ChangeType : INSERT_AFTER
    KeyPath : [2157, 0]
    InsertKeyPath : [null, 0]
    AttributeNames : [id, _PersonKey, _County, _Surname, _AGE, _DOB, _Country, _FirstName]
    AttributeValues : [2157, 10008/129, Vagzukarbsm, Gnnfzxxyqfgpsijcr, 110, Thu Dec 26 00:00:00 GMT 1901, Ekcqvrkoksr, Vwhm]
    When I try a group query on the same data, currently just trying to group by _DOB for every 10 years to count the number of people, I get no data change events fired, so don't get any data pushed to the client, though the data has been changed if I refresh the page.
    Any ideas ?

    can you include bam and jdev versions and also include exception from logs?

  • Is possible to see group currency data in SAP provide report or query ?

    Dear experts:
             Is possible to see group currency data in SAP provide report or query for Assets. When the Depreciation area currency is different with the group currency?
    My SAP version is ECC 6.0.
    Depreciation area currency: USD,
    Company code currency: USD,
    Second local currency: Group currency(TWD)

    You must have defined an additional dep area for group valuation too.
    then only you can get the asset values in TWD curency.

  • Getting data in a query on last date of all previous months

    Dear Experts,
    I need your help with a query.
    I am trying to create a query which when run should pick the number of Open Sales Order on the last date of all the previous months from the start of company.
    I could create the query for fetching the required data on last day of the previous month, say today is 25th June 2014, so my query only fetches data for May 31st 2014 but I need data for all previous month, May 31st 2014, April 30th 2014, March 31st 2014 & so on.
    Please advise how to achieve this is SQL query.
    Thanks & regards,
    Nitin

    Hi,
    Try this:
    Select *
    from(
    SELECT T0.[DocNum] as #,t0.cardcode as C, t0.docdate
    FROM ORDR T0
    WHERE T0.[DocStatus] = 'o' and T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-1,0)),10) OR T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-2,0)),10) or T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-3,0)),10) or T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-4,0)),10) or T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-5,0)),10) or T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-6,0)),10) or T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-7,0)),10)
    group by t0.cardcode,docdate,T0.[DocNum]) S
    pivot
    (count(#) for c in([cvt01],[cvt02],[cvt03],[cvt04],[cvt05],[cvt06],[cvt07],[cvt08],[cvt12])) P
    Note: Replace Cvt01,02...with your customer code.
    Thanks & Regards,
    Nagarajan

  • How to avoid grouping by date with dates as incoming parameters?

    Hello, I have the following Query from SAP Business One set as DataSource:
    SELECT  T1.SlpName as 'Vendor', convert(varchar(12), T0.[U_ER_PROV])as 'City', T0.[CardCode] as 'Client Code', T3.CardName as 'Client Name', T0.DocDate as 'Date', T2.ItemCode, T4.ItemName as 'Reference Description', sum (T2.Quantity) as 'Toal Units per Reference',
    avg (T2.Price)as 'Average Price', sum(T2.LineTotal) as 'Total'
    FROM ODLN T0
    INNER JOIN OSLP T1
    ON T0.SlpCode = T1.SlpCode
    INNER JOIN DLN1 T2
    ON T0.DocEntry = T2.DocEntry
    INNER JOIN OCRD T3
    ON T0.CardCode = T3.CardCode
    INNER JOIN OITM T4
    ON T2.ItemCode = T4.ItemCode
    group by  T1.SlpName, convert(varchar(12), T0.[U_ER_PROV]), T0.[CardCode], T4.ItemName, T0.DocDate, T2.ItemCode, T3.CardName
    order by  T1.SlpName, convert(varchar(12), T0.[U_ER_PROV]), T0.CardCode, T0.DocDate, T2.ItemCode
    What I´d like to do is, grouping in Crystal Reports, the result of this query by Item Code, not by date. The problem I have is that I need users introduce "from date" to "end date" as incoming paramater.
    The way I am running it, for example  I have some results like:
    date                         Item Code               Total
    01/01/2009               4646_R2                  120 u20AC
    10/01/2009               4646_R2                  34 u20AC
    And I´d like to take something like this:
    Item code                       Total
    4646_R2                         154 u20AC
    Not grouping by date ......
    Is there any way to do this using this query in Crystal Reports?
    Thanks very much for your time.
    Miguel A. Velasco

    Hello all, thanks very much to  Raghavendra for his helpfully answer.
    I followed your coments and now the report is running fine.
    Thanks again for your help without expecting anything in return.
    Miguel Velasco

  • Reg: Query group by problem

    Hi,
    I am trying to write query for report generation.According to my client requirment I need to calculate the difference
    between two date columns for "n" number of rows and i need to find the number of rows which are smaller
    than 2 and number of rows which are greater than 2 and calculate the percentage for number of rows which are smaller than 2.
    It must grouped by a third column
    I tried like this, but it shows that date column is not a grouped .....
    But I dont want to group that date column... Plz adivce....
    SELECT table1.column2,
          table2.column3,
          COUNT(*),
         CASE
                 WHEN TO_NUMBER (table1.DTT_column3 - table1.DTT_column4) <=2
                 THEN COUNT(*)
                 ELSE NULL
            END
             AS sucess_count,
         CASE
                 WHEN TO_NUMBER (table1.DTT_column3 - table1.DTT_column4) >2
                 THEN COUNT(*)
                 ELSE NULL
            END
            AS fail_count,
         FROM
         table1,
         table2
         WHERE table1.column1 =       table2.column2
         AND table1.column4 = value1
         GROUP BY table1.column2,table2.column3;TIA,
    Message was edited by: ORCL
    ORCLDB

    May be something like this.
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bi
    PL/SQL Release 10.2.0.2.0 - Production
    CORE    10.2.0.2.0      Production
    TNS for HPUX: Version 10.2.0.2.0 - Production
    NLSRTL Version 10.2.0.2.0 - Production
      1  with t
      2  as
      3  (select 1 id, to_date('01.02.2008','dd.mm.yyyy') date_1,
      4                to_date('03.02.2008','dd.mm.yyyy') date_2 from dual union all
      5   select 1,    to_date('03.02.2008','dd.mm.yyyy'),
      6                to_date('04.02.2008','dd.mm.yyyy') from dual union all
      7   select 2,    to_date('05.02.2008','dd.mm.yyyy'),
      8                to_date('06.02.2008','dd.mm.yyyy') from dual union all
      9   select 2,    to_date('01.02.2008','dd.mm.yyyy'),
    10                to_date('05.02.2008','dd.mm.yyyy') from dual
    11  )
    12  select count(case when to_number(date_2 - date_1) <= 2 then 1 end) diff_2,
    13        count(case when to_number(date_2 - date_1) > 2 then 1 end) diff_Greater_2,
    14    1 - (  count(case when to_number(date_2 - date_1) > 2 then 1 end)
    15         / count(case when to_number(date_2 - date_1) <= 2 then 1 end)
    16        ) percent
    17  from t
    18  group by rollup(id)
    19* having grouping_id(id) = 1
    SQL> /
        DIFF_2 DIFF_GREATER_2    PERCENT
             3              1 .666666667It will be always useful if you could post your full oracle version and a sample test data.
    Regards
    Raj

  • Grouping of Data in Advanced Datagrid

    Hii,
    I need to group the data in advanced datagrid. I used the Grouping collection class, but it it not working.
    My advanced datagrid has column groups...so will this have any impact on grouping.
    Thanks!!
    Vikas

    Assuming that the table (say WALK_IN_PER_LOG) that you have has atleast the following two columns
    walk_in_date DATE -- holds date time stamp
    dob DATE -- holds date of birth
    SELECT TO_CHAR(walk_in_date,'WW')&#0124; &#0124;'-'&#0124; &#0124;TO_CHAR(walk_in_date,'DAY') "Week#-Day"
    ,TO_CHAR(TRUNC(TO_CHAR(walk_in_date,'HH24')/02),'09')&#0124; &#0124;'-'&#0124; &#0124;
    TO_CHAR(TRUNC(TO_CHAR(walk_in_date,'HH24')/02)+2,'09')
    ,COUNT(*)
    FROM walk_in_per_log
    WHERE MONTHS_BETWEEN(SYSDATE,dob) > 18*12
    GROUP BY TO_CHAR(walk_in_date,'WW')&#0124; &#0124;'-'&#0124; &#0124;TO_CHAR(walk_in_date,'DAY')
    ,TO_CHAR(TRUNC(TO_CHAR(walk_in_date,'HH24')/02),'09')&#0124; &#0124;'-'&#0124; &#0124;
    TO_CHAR(TRUNC(TO_CHAR(walk_in_date,'HH24')/02)+2,'09')
    PS I might have complicated the query a little in trying to get the formatting as you had requested but the principle is simple
    First group by the day, so that all events of one day can be compared together, then extract the hour portion of each of those dates and divide by 2 and use the quotient of the division as a grouping factor.
    eg
    from hours
    00-02 the quotient is 0 (2 is taken as 1:59:59)
    02-04 the quotient is 1 (4 is taken as 3:59:59)
    and so on
    hope this helps....

  • Grouping the data

    Hello team,
    I have come up with a question at my work.
    I have a table that has several fields. When I group the data with one field, I get some counts which are equal to the original count of field before grouping. As I add more fields to the query and I add to my grouping, the my total count wouldn't be equal
    to the original count of the column.
    Can somebody please this?
    What query can take care of this?
    I generated this select statement, but it didn't work.
    SELECT DISTINCT c.code, c.Approved, Year(b.Date) AS [Year], Month(b.Date) AS [Month]
    FROM (SELECT a.Code, Sum(a.Approved) AS Approved FROM [MyTable1] AS a WHERE (((a.Approved)>0)) GROUP BY a.Code) 
    AS c INNER JOIN [MyTable2] AS b ON c. code = b. Code;
    Regards,
    GGGGGNNNNN
    GGGGGNNNNN

    Hi GGGGGNNNNN,
    I am not bale to understand the count of field means. Did it mean the numbers of records? If I understand correctly, I think the result is expected since the group by clause is changed.
    Here are some articles about SQL in Access for your reference:
    SELECT Statement (Microsoft Access SQL)
    GROUP BY Clause (Microsoft Access SQL)
    Regards & Fei
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Displaying a group of  data in different colums

    I have a problem with displaying a group of data in different colums. I want to display a group of data like this:
    Column 1 --- Column2 ----- Column3
    data1 data6 data11
    data2 data7 data12
    data3 data8 data13
    data4 data9 data14
    data5 data10 data15
    That is, the coulm headers must be at the same height of the page and data must be in paralell columns.
    My number of data is variable depending on a query result, and I want to start displaying my group on the first column and when it is full (the number of records per column is fixed), is must switch into the next one.
    In case there were more than 15 records, the 16th and the followings, must be displayed on the next page, with the same format as i have explained before.
    Thank you very much.

    Send me all files along with expected output at [email protected]

  • Query based on date partition

    Hi,
    I am trying to output only a successful job during the past 24 hrs of each day. If there is job that has an outcome of a success and a failure within the last
    24 hrs for each day, I want to only output the successful one. If there are no success for the same job, I will output the last attempted failed job.
    Here are my columns:
    current output:
    JOB_ID     JOBDATE               GROUP     PATH          OUTCOME          FAILED     LEVEL     ASSET
    3400908     7/27/2012 10:01:18 AM     polA     target1          Success          0     incr     clone1
    3400907     7/27/2012 10:01:09 AM     polA     target1          Failed          0     incr     clone1
    3389180     7/23/2012 10:01:14 AM     polA     target1          Failed          1     incr     clone1
    3374713     7/23/2012 10:01:03 AM     polA     target1          Success          0     incr     clone1
    3374712     7/22/2012 11:24:32 AM     polA     target1          Success          0     Full     clone1
    3367074     7/22/2012 11:24:00 AM     polA     target1          Failed          1     Full     clone1
    3167074     7/21/2012 10:01:13 AM     polA     target1          Success          0     incr     clone1
    336074     7/21/2012 10:01:08 AM     polA     target1          Success          0     incr     clone1
    desired output:
    JOB_ID     JOBDATE               GROUP     PATH          OUTCOME          FAILED     LEVEL     ASSET
    3400908     7/27/2012 10:01:18 AM     polA     target1          Success          0     incr     clone1
    3374713     7/23/2012 10:01:03 AM     polA     target1          Success          0     incr     clone1
    3374712     7/22/2012 11:24:32 AM     polA     target1          Success          0     Full     clone1
    3167074     7/21/2012 10:01:13 AM     polA     target1          Success          0     incr     clone1
    Here is a code I am trying to use without success:
    select *
    from
       (selectjob_id, jobdate, group, path, outcome, Failed, level, asset,
              ROW_NUMBER() OVER(PARTITION BY group, path, asset ORDER BY jobdate desc) as rn
                   from job_table where jobdate between trunc(jobdate) and trunc(jobdate) -1 )
       where rn = 1
       order by jobdate desc;Thanks,
    -Abe

    Hi, Abe,
    You're on the right track, using ROW_NUMBER to assign numbers, and picking only #1 in the main query. The main thing you're missing is the PARTITION BY clause.
    You want to assign a #1 for each distinct combination of group_id, path, asset and calendar day , right?
    Then you need to PARTITION BY group_id, path, asset and calendar day . I think you realized that when you named this thread "Query Based *on date partition* ".
    The next thing is the analytic ORDER BY clause. To see which row in each partition gets assigned #1, you need to order the rows by outcome ('Success' first, then 'Failed'), and after that, by jobdate (latest jobdate first, which is DESCending order).
    If so, this is what you want:
    WITH     got_r_num     AS
         SELECT  j.*     -- or list columns wanted
         ,     ROW_NUMBER () OVER ( PARTITION BY  group_id     -- GROUP is not a good column name
                                   ,                    path
                             ,             asset
                             ,             TRUNC (jobdate)
                                   ORDER BY          CASE  outcome
                                                 WHEN  'Succcess'
                                         THEN  1
                                         ELSE  2
                                             END 
                             ,             jobdate     DESC
                           )      AS r_num
         FROM    job_table  j
         WHERE     outcome     IN ('Success', 'Failed')
    --     AND     ...     -- Any other filtering, if needed
    SELECT     *       -- or list all columns except r_num
    FROM     got_r_num
    WHERE     r_num     = 1
    ;If you'd care to post CREATE TABLE and INSERT statements for the sample data, then I could test it.
    It looks like you posted multiple copies of this thread.  I'll bet that's not your fault; this site can cause that.  Even though it's not your fault, please mark all the duplicate versions of this thread as "Answered" right away, and continue in this thread if necessary.
    Edited by: Frank Kulash on Jul 28, 2012 11:47 PM
    This site is flakier than I thought! I did see at least 3 copies of this same thread earlier, but I don't see them now.

  • Between operator for group by date in Apex Interactive Reports

    Hi,
    In the interactive reports filter, i couldn't find the 'between' operator for date field (got a 'group by date' in my sql query (source). I am just wondering, Is it beacuse of the group by date clause?. Is there any way to show the 'between' operator in the interactive reports filter.
    Thanks

    I just opened an existing IR style report, went to actions, filter, selected a date column and found between at the bottom of the list of values.. Are you sure the date you are trying to filter on is a true date column?
    Thank you,
    Tony Miller
    Webster, TX
    What if you really were stalking a paranoid schizophrenic... Would they know?
    If this question is answered, please mark the thread as closed and assign points where earned..

  • Group By - Date: Web Service vs. Out of the Box

    When selecting the drop down to group by Date in the Out of the Box Search application, the groups are delivered as:
    - Within the last day
    - Within the last week
    - Within the last month
    - etc...
    But through the web service when we group by lastmodifieddate (or any other date attribute), the groups are separated by specific dates and not ranges. Is there a setting on the GroupAttribute object that you can use to have the groups return in date ranges? Or is the out of the box arranging these groups into date ranges manually?
    My gut tells me that the groupingOption on the oracle.search.query.webservice.client.GroupAttribute has a reserved value for date ranges, but the 11.1.2.0.0 API says that only a value of "EQUALITY" is supported. Either that or the optionParameter on the same object, but I couldn't find an example of any values that can be used in it.

    If BO is behind firewall then it is better to use Web Services SDK. Whenever Business Objects is installed the Web Service provider dswsbbobje is installed by default along with other out of box web applications such as InfoViewApp or CmcApp.
    The WS SDK assemblies are at:
    <Business Objects root>\BusinessObjects Enterprise 12.0\web services\en\dsws_consumer\data\dswsdotnet2API or
    <Business Objects root>\BusinessObjects Enterprise 12.0\web services\en\dsws_consumer\data\dswsdotnetAPI
    Include them in your Bin directory depending on version of .NET you use.
    Write consumer application that calls into dswsbobje provider to get the report. Please check the [WS developer guide|http://help.sap.com/businessobject/product_guides/boexir31/en/wssdk_dg_12_en.zip] and [API Reference|http://help.sap.com/businessobject/product_guides/boexir31/en/wssdk_net_apiRef_12_en.chm] for further help. There are code snippets and details information in both places.

  • Grouping a data small datetime

    Hi guys, I got data that come from Oracle, finally I got a good structure , everything is good but this issue:
    203 2013-04-18 14:45:19.0000000  100
    203 2013-04-18 14:45:25.0000000    85
    just as sample, I shoud group th id 203 as
    203 2013-04-18 185
    I tried with convert, cast, day, year and everything but always the result is splitted in two rows. I don have idea at the moment how I can group the data from thet format to another format ( but more important I don't want the 203 splitted and in the same
    time I need the data...)
    Any advice? Thanks

    Can you give us the DDL+DML?
    Did you try this query?
    select id,CAST(CAST(currentdate as varchar(11)) as date),SUM(cnt) from @T
    group by id,CAST(CAST(currentdate as varchar(11)) as date)
    --Prashanth

  • Displaying a SharePoint List in a ListView Control with Grouping by Date

    Dear All
    I have created a ListView to display items from a SharePoint list:
    <asp:ListView ID="UpAndComingEventsLV" runat="server">
    <LayoutTemplate>
    <ul>
    <li id="itemPlaceholder" runat="server" />
    </ul>
    </LayoutTemplate>
    <ItemTemplate>
    <li id="Li1" runat="server">
    <asp:Literal ID="CurrentDate" runat="server" />
    <%#Eval("Title")%> <%#Eval("Event_x0020_Category")%> <%#Eval("EventDate", "{0:HH:mm}")%>
    </li>
    </ItemTemplate>
    </asp:ListView>
    To perform the binding and then display the date I'm doing the following:
    Using oSiteCollection As New SPSite(_ListPath)
    Using web As SPWeb = oSiteCollection.OpenWeb()
    List = web.GetList(_ListPath)
    End Using
    End Using
    Dim Query As New SPQuery
    Query.Query = "<Where><And><Eq><FieldRef Name='Status' /><Value Type='Choice'>Approved</Value></Eq><Geq><FieldRef Name='EventDate' /><Value Type='DateTime'><Today Offset='4' /></Value></Geq></And></Where><OrderBy><FieldRef Name='EventDate' /></OrderBy>"
    'Query.RowLimit = 1
    Query.ViewFields = "<FieldRef Name='Event_x0020_Category' /><FieldRef Name='Title' /><FieldRef Name='EventDate' /></ViewFields>"
    Dim ItemColl As SPListItemCollection = List.GetItems(Query)
    UpAndComingEventsLV.DataSource = ItemColl.GetDataTable
    UpAndComingEventsLV.DataBind()
    dfgdfgfg
    I would like to group my events by date though, rather than display the date against each row. To make things even more complicated, I would like to use friendly names like Today, Tomorrow, Monday, Tuesday instead of dates:
    TODAY
    Event number one
    Event number two
    Event number three
    TOMORROW
    Event number 4
    Event number 5
    MONDAY
    Event number 6
    Event number 7
    At the moment, I've created a ItemDataBound event on the ListView control and I have been able to display the Today, Tomorrow, Monday etc bit but I can't figure out the best way to perform the grouping. Incidentally, I only want to group on the date not
    on time:
    Private Sub UpAndComingEventsLV_ItemDataBound(sender As Object, e As Web.UI.WebControls.ListViewItemEventArgs) Handles UpAndComingEventsLV.ItemDataBound
    If e.Item.ItemType = Web.UI.WebControls.ListViewItemType.DataItem Then
    'Retrieve data item
    Dim DataItem As ListViewDataItem = DirectCast(e.Item, ListViewDataItem)
    Dim RowView As DataRowView = DirectCast(DataItem.DataItem, DataRowView)
    Dim EventDate As DateTime = RowView("EventDate")
    'Get literal control
    Dim CurrentDate As Literal = e.Item.FindControl("CurrentDate")
    'Display friendly date
    If Not IsNothing(CurrentDate) Then
    Select Case EventDate.Date
    Case Is = Now.Date
    CurrentDate.Text = "Today"
    Case Is = Now.Date.AddDays(1)
    CurrentDate.Text = "Tomorrow"
    Case Is = Now.Date.AddDays(2)
    CurrentDate.Text = Now.Date.AddDays(2).DayOfWeek.ToString
    Case Is = Now.Date.AddDays(3)
    CurrentDate.Text = Now.Date.AddDays(3).DayOfWeek.ToString
    Case Is = Now.Date.AddDays(4)
    CurrentDate.Text = Now.Date.AddDays(4).DayOfWeek.ToString
    Case Is = Now.Date.AddDays(5)
    CurrentDate.Text = Now.Date.AddDays(5).DayOfWeek.ToString
    Case Is = Now.Date.AddDays(6)
    CurrentDate.Text = Now.Date.AddDays(6).DayOfWeek.ToString
    End Select
    Else
    CurrentDate.Text = "-"
    End If
    End If
    End Sub
    Please could you help me understand the best way to perform the grouping by date?
    Any help or advice is greatly appreciated!
    Many thanks
    Daniel

    When I've done this in the past I've always used a calculated field that translated the days into the groupings I wanted.  You couldn't do quite the groupings that you list above, but it would give you categories to group on.  You could then
    apply the groupings in the base view.  Then you could use the Row Databound event to change the labels on the Groupings at runtime to the ones you want to use.
    Paul Stork SharePoint Server MVP
    Principal Architect: Blue Chip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

Maybe you are looking for

  • How do i copy my music from an iTunes library installed on a pc

    Hi, I would like to copy my itunes library from my old pc to my McBookAir. How shall I proceed ? Thanks

  • Assassin's Creed Wont Play

    I just purchased an downloaded the Assassin's Creed game for my iPod Touch. After searching the net and Apple support I haven't found anyone else with this problem so I decided to ask here. After downloading and syncing, the "game" only plays a trail

  • Trying to register my copy of Elements 13, the program won't let me enter the code.

    I purchased a copy of Elements 13 from amazon.ca and, when I try to activate the program, I get to the place where I'm to enter the code but the page won't let me enter the code. The code includes letters and numbers but the page only allows me to en

  • IPhone 3.0 OS for Free?

    I've purchased my iPod Touch less than thirty days before the release of the OS update. Being that it's so close, does Apple have any OS update grace periods so I don't have to pay for an update I would've had if I had waited a few more days? Who wou

  • Jdeveloper Data Source control and xml file

    Hi I was wundering if Jdeveloper can parse a xml file and and show the results in a grid for a xml file just like the webservice control. like here http://www.oracle.com/technology/obe/obe11jdev/11/wsdc/wsdc.htm regards