GROUP BY+COUNT+SUM SQL

Hi,
I have a table, it has 2 colunms, ( name,number)
name number
B1 7
B1 7
B1 28
B1 28
B1 28
B2 7
B2 28
B3 7
I want to see below
number
name sum 7sum 28sum
B1 5 2 3
B2 2 1 1
B3 . . .
CAN YOU HELP ME
THANK YOU VERY MUCH FOR HELP

Like this?
SQL> ed
Wrote file afiedt.buf
  1  with t as (select 'B1' as name, 7 as num from dual union all
  2             select 'B1', 7 from dual union all
  3             select 'B1', 28 from dual union all
  4             select 'B1', 28 from dual union all
  5             select 'B1', 28 from dual union all
  6             select 'B2', 7 from dual union all
  7             select 'B2', 28 from dual union all
  8             select 'B3', 7 from dual)
  9  --
10  -- end of test data - use query below
11  --
12  select name
13        ,count(*)
14        ,sum(decode(num,7,1,0)) as sum7
15        ,sum(decode(num,28,1,0)) as sum28
16  from t
17  group by name
18* order by 1
SQL> /
NA   COUNT(*)       SUM7      SUM28
B1          5          2          3
B2          2          1          1
B3          1          1          0

Similar Messages

  • DIFFERENCE BETWEEN SUM AND COUNT IN SQL

    DIFFERENCE BETWEEN SUM AND COUNT IN SQL
    WHAT IS THE DIFFERENCE VERIFY IN DETAIL/

    21031980, I suggest you upgrade your computer sothat you can access google.
    lol.
    wtfpwnd.Google is also helpful for understanding the strange
    acronyms that show up around here lately (yes, I did
    find and understand this one). :-)Haha, sorry!
    It's the inner-gamer in me rearing its ugly head...
    :-)

  • Two count(*) in sql statement

    hi viewers,
    I need the similar query in oracle for the following Informix query.
    select count(*),(select count(*) from table_name where col1=10) from table_name where col1=10;
    i have a solution also but the problem is, if that table has no rows then output is not 0,0
    select count(*),(select count(*) from table_name where col1=10) from table_name where col1=10 group by col1;
    thanks
    hari

    A little remark: the behavoiur you stick on is a default feature in Oracle:
    SQL> select count(*) from emp where deptno = 40;
      COUNT(*)
             0
    SQL> select count(*) from emp where deptno = 40 group by deptno;
    no rows selectedThese two queries work differ. It is described in Oracle documentation:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions001.htm#i89203
    Oracle applies the aggregate functions to each group of rows and returns a single result row for each group.
    If you omit the GROUP BY clause, then Oracle applies aggregate functions in the select list to all the rows in the queried table or view
    As Alex pointed out, you should not include group by clause and should use count(*) instead of a subquery.
    Rgds.

  • SCCM Report- Count of SQL Servers installed in my enviroment

    Hello everyone,
    I need to give count of SQL server installed in my organization for auditing.
    i want the count of sql server edition wise ,for example,
    SOFTWARE                                         COUNT
    Microsoft SQL server 2008 express - 1000
    Microsoft SQL server 2010 standard - 525
    There are SQL servers 2005 to 2012 including all editions in my organization.
    PLEASE anyone help me.
    We have SCCM 2007 in my enviroment.

    I am getting this error as i pulled a report
    Invalid object name 'v_gs_sql_property0'.
    Error Number:
    -2147217865
    Source:
    Microsoft OLE DB Provider for SQL Server
    Native Error:
    208
    REPORT SQL QUERY
    select sys1.Netbios_name0,
    max(Case sql.PropertyName0 when 'SKUName' then
       sql.PropertySTRValue0 end) as [SQL08 Type]
    ,max(Case sql.PropertyName0 when 'SPLEVEL' then
       sql.PropertyNUMValue0 end) as [SQL08 Service Pack]  
    ,max(Case sql.PropertyName0 when 'VERSION' then
       sql.PropertySTRValue0 end) as [SQL08 Version]
    ,max(Case sql.PropertyName0 when 'FILEVERSION' then
       sql.PropertySTRValue0 end) as [SQL08 CU Version]
    ,max(Case sql.PropertyName0 when 'INSTANCEID' then
       sql.PropertySTRValue0 end) as [SQL08 InstanceID]
    ,max(Case sql2.PropertyName0 when 'SKUName' then
       sql2.PropertySTRValue0 end) as [SQL05 Type]
    ,max(Case sql2.PropertyName0 when 'SPLEVEL' then
       sql2.PropertyNUMValue0 end) as [SQL05 Service Pack]
    ,max(Case sql2.PropertyName0 when 'VERSION' then
       sql2.PropertySTRValue0 end) as [SQL05 Version]
    ,max(Case sql2.PropertyName0 when 'FILEVERSION' then
       sql2.PropertySTRValue0 end) as [SQL05 CU Version]
    ,max(Case sql2.PropertyName0 when 'INSTANCEID' then
       sql2.PropertySTRValue0 end) as [SQL05 InstanceID]
    from v_r_system sys1
    left join v_gs_sql_property0 sql on sys1.resourceid=sql.ResourceID
    left join v_gs_sql_property_legacy0 sql2 on sys1.ResourceID=sql2.ResourceID
    where sql.PropertyName0 in ('instanceid','SKUNAME','SPLevel','version','fileversion')
    or
    sql2.PropertyName0 in ('instanceid','SKUNAME','SPLevel','version','fileversion')
    group by sys1.Netbios_name0

  • SSISB Row Counts in SQL Server 2012

    Does SSISDB (SQL Server 2012) track row counts such as total rows loaded, inserted rows, and updated rows?
    Or do we still need to use the row count transformation to capture these counts?
    Ryan P. Casey • <a href="http://www.R-P-C-Group.com">www.R-P-C-Group.com</a>

    Hi RPCASEY001,
    Based on my research, Row Counts for Execute SQL Task do not get captured in [SSISDB].[internal].[execution_data_statistics] table even when logging on the SSISDB server is set to Verbose. As per my understanding, this makes sense that how would SSIS know
    what the affected row counts are by the SQL statement in an Execute SQL Task given that we can put whatever we want in there?
    If we want to capture row counts loaded using the Execute SQL task, we can create a log table and add the row counts column into the log table. For more details, please refer to the following blog:
    http://consultingblogs.emc.com/jamiethomson/archive/2005/06/11/SSIS_3A00_-Custom-Logging-Using-Event-Handlers.aspx
    The following similar thread is for your reference:
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/64ab1ec3-b0f2-4bba-9523-a7bcd6c154f1/ssis-logging-recording-record-count-from-sql-task?forum=sqlintegrationservices
    Thanks,
    Katherine Xiong
    If you have any feedback on our support, please click
    here.
    Katherine Xiong
    TechNet Community Support

  • Help with GROUP BY with SUM

    Hello all:
    I have always struggled with getting this right, so hopefully someone can assist with this. 
    Basically I have two tables:
    CREATE TABLE [dbo].[Placement](
    [PlacementID] [int] IDENTITY(1,1) NOT NULL,
    [TravelerID] [int] NOT NULL,
    [ActivityTypeID] [int] NULL,
    [ActivityStatusID] [int] NULL,
    [StartDate] [datetime] NULL,
    [EndDate] [datetime] NULL,
    [NumberOfWeeks] [int] NULL,
    [BookingCompanyID] [int] NOT NULL
    CREATE TABLE [dbo].[TravelerCompanyData](
    [TravelerID] [int] NOT NULL,
    [CompanyID] [int] NOT NULL,
    [StatusID] [int] NOT NULL
    I am trying to join the placement table to the TravelerCompanyData table so that I only get one row per TravelerID. The point of this query is to sum up the number of weeks. So I want to sum the number of weeks of Placements that have been completed (if
    any), and add them to however many week the person has been currently on assignment. I cannot use the NumberOfWeeks column if a placement is currently "On Assignment" because it counts the number of weeks from the start date to the end date, and
    the Traveler will not be all the way to the end date yet.
    However, I think with my SUMs in there and all the columns I am referencing in the CASE statement, I am not getting the grouping right. 
    The query below will yield four columns, one for each sum because there are four separate rows in the placement table that fit the criteria of the JOIN/WHERE
    Some notes:
    ActivityStatusID = 23 means the placement status is "on assignment"
    = 24 means the placement in "complete"
    CompanyID 10 and 12 are the only companies that I want to fit this summing criteria. 
    I am using only one travelerID to simplify the result set. 
    SELECT
    trav.TravelerID
    ,CASE
    WHEN p2.EndDate IS NULL -- Not on assignment, can sum number of weeks
    THEN SUM(p.NumberOfWeeks)
    ELSE -- multiple assignments, count weeks
    CASE
    WHEN (DATEDIFF(day, p2.StartDate, GETDATE()) + 1) % 7 < 3
    THEN (DATEDIFF(day, p2.StartDate, GETDATE()) + 1) / 7
    +
    ISNULL(p.NumberOfWeeks,0)
    WHEN (DATEDIFF(day, p2.StartDate, GETDATE()) + 1) % 7 >= 3
    THEN (DATEDIFF(day, p2.StartDate, GETDATE()) + 1) / 7 + 1
    +
    ISNULL(p.NumberOfWeeks,0)
    END
    END AS WksOnAssignment
    FROM TravelerCompanyData trav
    -- Completed placements ------------------
    LEFT JOIN dbo.Placement p ON p.TravelerID = trav.TravelerID
    AND p.ActivityStatusID IN (24)
    AND trav.CompanyID = p.BookingCompanyID
    -- Placement if on assignment ------------
    LEFT JOIN dbo.Placement p2 ON p2.TravelerID = trav.TravelerID
    AND p2.ActivityStatusID IN (23)
    AND trav.CompanyID = p2.BookingCompanyID
    WHERE ( trav.CompanyID IN (10,12))
    AND
    ( p.PlacementID IS NOT NULL
    OR
    p2.PlacementID IS NOT NULL )
    AND trav.TravelerID = 31788
    GROUP BY trav.TravelerID
    ,p.NumberOfWeeks
    ,p2.StartDate
    ,p2.EndDate
    If I add the NumberOfWeeks column in, it is adding that number to the number of weeks the current On Assignment placement currently has for each row (56 weeks), but I need to add that 56 weeks to the sum of the NumberOfWeeks column. Here is the result set:
    TravelerID NumberOfWeeks WksOnAssignment
    31788 8 64
    31788 12 68
    31788 25 81
    31788 33 89
    So am I joining wrong, grouping wrong, or summing wrong? 
    Thanks so much for any pointers!!!

    Thanks for the reply. I did some more experimenting and I discovered I don't need the SUM in this case at all. I get the same results when remove the SUM completely, but still GROUP BY the same columns. 
    Alternatively, if I SUM and the only GROUP BY tcd.TravelerID, I will get one row, but it is summing each NumberOfWeeks value by the result of the expression. 
    Query where I have included the NumberOfWeeks from the p Placement join, and the StartDate and EndDate of p2 Placement table (on assignment match) - NOTE: I have noticed that with this query, the SUM makes no difference:
    SELECT
    trav.TravelerID
    ,p.NumberOfWeeks
    ,p2.StartDate
    ,p2.EndDate
    ,CASE
    WHEN p2.EndDate IS NULL -- Not on assignment, can sum number of weeks
    THEN p.NumberOfWeeks
    ELSE -- multiple assignments, count weeks
    CASE
    WHEN (DATEDIFF(day, p2.StartDate, GETDATE()) + 1) % 7 < 3
    THEN (DATEDIFF(day, p2.StartDate, GETDATE()) + 1) / 7
    +
    ISNULL(p.NumberOfWeeks,0)
    WHEN (DATEDIFF(day, p2.StartDate, GETDATE()) + 1) % 7 >= 3
    THEN (DATEDIFF(day, p2.StartDate, GETDATE()) + 1) / 7 + 1
    +
    ISNULL(p.NumberOfWeeks,0)
    END
    END AS WksOnAssignment
    FROM TravelerCompanyData trav
    -- Completed placements ------------------
    LEFT JOIN dbo.Placement p ON p.TravelerID = trav.TravelerID
    AND p.ActivityStatusID IN (24)
    AND trav.CompanyID = p.BookingCompanyID
    -- Placement if on assignment ------------
    LEFT JOIN dbo.Placement p2 ON p2.TravelerID = trav.TravelerID
    AND p2.ActivityStatusID IN (23)
    AND trav.CompanyID = p2.BookingCompanyID
    WHERE ( trav.CompanyID IN (10,12))
    AND
    ( p.PlacementID IS NOT NULL
    OR
    p2.PlacementID IS NOT NULL )
    AND trav.TravelerID = 31788
    GROUP BY trav.TravelerID
    ,p.NumberOfWeeks
    ,p2.StartDate
    ,p2.EndDate
    Gives:
    TravelerID NumberOfWeeks StartDate EndDate WksOnAssignment
    31788 8 2013-04-01 2014-10-04 64
    31788 12 2013-04-01 2014-10-04 68
    31788 25 2013-04-01 2014-10-04 81
    31788 33 2013-04-01 2014-10-04 89
    See it is summing correctly on the row, but how can I get it to sum the NumberOfWeeks column and add it to 56, which is what the calculation yields from the StartDate of the "On Assignment" placement from p2 until today's date?
    Hope that makes sense! 

  • Showing column value as counter in sql query - report

    I created a classic report with search bar based on an sql query. I would like to show the "notes" column in this query using some sort of counter and as a hyperlink to another section on the page (same idea as footnotes in a book). So if I have 10 rows and 5 have "notes". I should show 1,2,3,4,5 in the notes column for those rows and the number gets displayed as a link to another section listing the notes 1 through 5.
    I was thinking of creating a hidden page item as the counter with value of 0 and then in my query doing counter+1 but i'm not sure how to do this or if i can do that...
    If anyone can help or have any other ideas I would really appreciate it!!
    Thanks,
    Hindy

    Well, I'm doing this in VB and the subquery is dynamic. I'm passing an ADO recordset to a routine that sets up a listview to display the results. The number of columns selected can vary. My idea was to size the columns appropriately based on the size of the data. Within the display routine I could:
    sql = "SELECT "
    for i = 0 to oRS.Fields.Count - 1
    sql = sql & "MAX(LENGTH(" & i & ")), "
    next 'i
    sql = sql & "FROM (" & oRS.Source & ")"

  • How to use group by in PL/SQL

    Can anyone give me a clue how to group rows using PL/SQL? I want to make a push button that groups a number of rows. When I run the form and push the button, I get the Oracle 01422 error. I am using one data block and, after pressing execute on the Oracle form in the web browser, I want to sort the rows using the group by clause as a pl sql trigger in a push button (with the WHEN BUTTON PRESSED trigger). I am new to Oracle Forms.

    I managed to use a cursor to access and display each row. I have to press the command button I created once for access of each row individually. I want to be able to push the button once, and populate each row with a record from my table. I am using the tabular format. Here is my code:
    DECLARE
         CURSOR email_message_cur
         IS
              SELECT sender, subject, body, date_time_sent
              FROM Email_Message
              ORDER BY sender;
    BEGIN
         OPEN email_message_cur;
         FETCH email_message_cur
         INTO :GROUP_EMAIL_MESSAGE.SENDER, :GROUP_EMAIL_MESSAGE.SUBJECT, :GROUP_EMAIL_MESSAGE.BODY, :GROUP_EMAIL_MESSAGE.DATE_TIME_SENT;
         WHILE email_message_cur%FOUND LOOP
              IF :GROUP_EMAIL_MESSAGE.SENDER IS NOT NULL THEN
                   CREATE_RECORD;
              END IF;
              FETCH email_message_cur INTO :GROUP_EMAIL_MESSAGE.SENDER, :GROUP_EMAIL_MESSAGE.SUBJECT, :GROUP_EMAIL_MESSAGE.BODY, :GROUP_EMAIL_MESSAGE.DATE_TIME_SENT;
         END LOOP;
         CLOSE email_message_cur;
    END;

  • Group and count

    Hello Friends,
    I have a query where I select organization, item_num, and transaction_date.
    I need to group and count the result by transaction_date, so I will have 3 groups:
    First - will count records where transaction_date falls between the 1st and 10th of the month.
    Second - will count records where transaction_date falls between the 11th and 20th of the month.
    Third - will count records where transaction_date falls between the 21st and 31st of the month.
    The result of this count will be used in the Oracle Report.
    Please, give me your advise on how I can achive this.
    Thank you.

    select organization,
           item_num,
           count(case
                   when transaction_date between trunc(transaction_date, 'mm') and trunc(transaction_date, 'mm') + 9 then 1
                 end) "1-10",
           count(case
                   when transaction_date between trunc(transaction_date, 'mm') + 10 and trunc(transaction_date, 'mm') + 19 then 1
                 end) "11-20",
           count(case
                   when transaction_date between trunc(transaction_date, 'mm') + 20 and trunc(last_day(sysdate)) then 1
                 end) "21-end"
      from mytable
    group by organization, item_num
    Ramin Hashimzade

  • Get the connected users count from sql server using powershell

    Hi,
    I am working on SharePoint 2013,I am having SQL server 2012.
    I want to get the Connected Users count from  sql server using power shell.
    Can any one please let me know how to implement.
    Thanks in advance.
    Regards,
    Phani Kumar R

    Sorry Tom, I dont like to hear "There is no way" :-(
    There is always a way in computer to get what you need (at least it is good as Rule of thumb). I am not sure we will find it here (in a voluntary supporting forum).
    Now we (or better the architect of their system) should think of the way :-)
    Of course doing so in the forum, while we do know the system and only got a glimpse on what is needed, is not the best idea. I will point some issues which can be related to a solution. Those are not a solotions as it is but something we can use for a solution
    once something look in the right way.
    * A web connects counter is one of the easier thing to do. The basic idea is just to use the connect event and the disconnect event an adding 1 or removing 1 from the counter. This is best to do in the application using static variable as any way the second
    the application is down the counter can be go to hell as we know there is no one connect (there for a counter do not use database usually). Using a web dot-net (or asp 3) application this is done most of the time using the global.asa/global.asax file, which
    include the application and session events. for example using the method Session_Start
    protected void Session_Start(object sender, EventArgs e) {
    // Code that runs when a new session is started
    * IIS have a build-in loging system where we can log each and every request/response or only logins users. There is lot we can do with this log files including data mining. Using small bulk insert script we can use the SQL agent to insert those logs to the
    database and get the information we need.
    * any web developer i want to believe know about the Fiddler application which we use to monitor traffic. A proxy is not the only way to to monitor traffic (it is not good for our case as this is in the client side), there are several option in the server
    side.
    * SQL trigger on logon can be use to get information on who is loging on and can be logging only specific source (like our sharepoint IP or any sharepoint application). This information (what is the application which connect to the server can be retrive
    in several solution without using a trigger as well)
    *** (I'll be brief ... I'm getting bored... probably the reader feel the same)
    * using extended events and/or profiler we can monitor any connection and save the data or just remember it in shared (static) variable (this
    blog show how to do it by the way). Again we can monitor specific application or use any filter in order to get only the sharepoint users
    .... and i can continue for several days more :-) ...
    "If there is a willing, then there's a way"
    "If you can't do it, Then someone else probably can"
    "Never say never"
    I hope this help somehow :-)
    [Personal Site] [Blog] [Facebook]

  • 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

  • Group 5 min sum of count

    Hi
    I am looking for a sum of status count by group of 5 min from given date-time.
    I have table table1 with columns update_datetime date, status char(1)
    Can any one suggest a solution for it? Thanks in advance.
    I have a query but want to modify it to get the sum of status group by 5 min -
    SELECT update_datetime , decode(status,'1','SUBMITTED') status,COUNT (1)
    FROM test1
    WHERE to_char(update_datetime, 'dd-mon-yyyy hh24:mi:ss') >= '24-jan-2010 14:00:00'
    and to_char(update_datetime, 'dd-mon-yyyy hh24:mi:ss') < '24-jan-2010 14:16:00'
    AND status = '1'
    GROUP BY update_datetime, status
    order by update_datetime;
    UPDATE_DATETIME     STATUS
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:00:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:01:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:02:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:03:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:04:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:05:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:06:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:07:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:08:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:09:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:10:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:11:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:12:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:13:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:14:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:15:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    24/01/2010 14:16:00 1
    Edited by: SDD on Feb 3, 2010 11:18 AM

    Something like this:
    SQL> WITH subq_times AS
      2   (SELECT SYSDATE + ROWNUM/(24*60) dt
      3    FROM dual
      4    CONNECT BY ROWNUM <= 20)
      5  SELECT dt, TRUNC(dt) + TRUNC(TO_CHAR(dt,'SSSSS')/300)/12/24 group_by_me
      6  FROM   subq_times
      7  ORDER BY dt;
    DT                  GROUP_BY_ME
    03/02/2010 11:32:53 03/02/2010 11:30:00
    03/02/2010 11:33:53 03/02/2010 11:30:00
    03/02/2010 11:34:53 03/02/2010 11:30:00
    03/02/2010 11:35:53 03/02/2010 11:35:00
    03/02/2010 11:36:53 03/02/2010 11:35:00
    03/02/2010 11:37:53 03/02/2010 11:35:00
    03/02/2010 11:38:53 03/02/2010 11:35:00
    03/02/2010 11:39:53 03/02/2010 11:35:00
    03/02/2010 11:40:53 03/02/2010 11:40:00
    03/02/2010 11:41:53 03/02/2010 11:40:00
    03/02/2010 11:42:53 03/02/2010 11:40:00
    03/02/2010 11:43:53 03/02/2010 11:40:00
    03/02/2010 11:44:53 03/02/2010 11:40:00
    03/02/2010 11:45:53 03/02/2010 11:45:00
    03/02/2010 11:46:53 03/02/2010 11:45:00
    03/02/2010 11:47:53 03/02/2010 11:45:00
    03/02/2010 11:48:53 03/02/2010 11:45:00
    03/02/2010 11:49:53 03/02/2010 11:45:00
    03/02/2010 11:50:53 03/02/2010 11:50:00
    03/02/2010 11:51:53 03/02/2010 11:50:00
    20 rows selected.
    SQL> WITH subq_times AS
      2   (SELECT SYSDATE + ROWNUM/(24*60) dt
      3    FROM dual
      4    CONNECT BY ROWNUM <= 20)
      5  SELECT TRUNC(dt) + TRUNC(TO_CHAR(dt,'SSSSS')/300)/12/24 group_by_me
      6  ,      COUNT(*)
      7  FROM   subq_times
      8  GROUP by TRUNC(dt) + TRUNC(TO_CHAR(dt,'SSSSS')/300)/12/24
      9  ORDER BY 1;
    GROUP_BY_ME           COUNT(*)
    03/02/2010 11:30:00          2
    03/02/2010 11:35:00          5
    03/02/2010 11:40:00          5
    03/02/2010 11:45:00          5
    03/02/2010 11:50:00          3
    SQL>

  • SQL : Good Review Exercise (JOIN, USING, COUNT, SUM, ON, WHERE, LEFT...)

    Back to school, I'm already stumped on this review question. Its been a while...and I think there have been a few changes to the NATURAL JOIN statements. Any guidance would be appreciated.
    the following are abreviated....
    T_CUST
    custnum c_last curbal slsnum
    124...........adams........418.33......3
    256...........samuels.....494.44.......6
    311...........ford............43.43.........8
    T_REP
    slsnum s_last totcom
    3..............bush........3454
    6..............pooch.......434
    8..............kooch.......4
    Display the number of customers each rep has, along with a total of their balances.
    I have this so far but its way off.....
    SQL> SELECT slsrnum, c_last, s_last
    2 FROM (SELECT slsrnum, c_last, s_last
    3 FROM ct_ust OUTER JOIN t_rep
    4 USING(slsrnum)
    5 ORDER BY slsrnum, c_last);
    Thanks for the time, its a simple query, but i'm stuck....!!>>!>

    If you want that in ANSI syntax, it would br:
    SELECT r.slsnum AS "Rep #", COUNT(*) AS "# of Cust",
           SUM(curbal) AS "Total Balances"
    FROM t_rep r
         LEFT OUTER JOIN t_cust c ON r.slsnum = c.slsnum
    GROUP BY r.slsnum; However, are you sure that you actually need the outer join? Are there really salesmen without customers? If so, how do you want them to show. With the outer join, if I add a salesman without customers:
    INSERT INTO T_REP VALUES (4,'smith',0);Then with the outer join I get:
    SQL> SELECT r.slsnum AS "Rep #", COUNT(*) AS "# of Cust",
      2         SUM(curbal) AS "Total Balances"
      3  FROM t_rep r
      4       LEFT OUTER JOIN t_cust c ON r.slsnum = c.slsnum
      5  GROUP BY r.slsnum;
         Rep #  # of Cust Total Balances
             3          1         418.33
             4          1
             6          1         494.44
             8          1          43.43Which seems wrong to me. Minimally, you would need to do something more like:
    SQL> SELECT r.slsnum AS "Rep #", COUNT(c.custnum) AS "# of Cust",
      2         SUM(curbal) AS "Total Balances"
      3  FROM t_rep r
      4       LEFT OUTER JOIN t_cust c ON r.slsnum = c.slsnum
      5  GROUP BY r.slsnum;
         Rep #  # of Cust Total Balances
             3          1         418.33
             4          0
             6          1         494.44
             8          1          43.43and, if you want 0 for the balance, then I would do:
    SELECT r.slsnum AS "Rep #", COUNT(c.custnum) AS "# of Cust",
           NVL(SUM(curbal), 0) AS "Total Balances"
    FROM t_rep r
         LEFT OUTER JOIN t_cust c ON r.slsnum = c.slsnum
    GROUP BY r.slsnum; Without the outer join, then salesman 4 wouild not appear on the list at all.
    But, as I said before, are there really salesmen without customers?
    John

  • Get Column sum, count in sql developer

    Dear All seniors,
    I need help in oracle sql developer that after select statement when we got our result in below rows and coloums,
    then how to get its sum, count, etc.
    as in pl sql developer we simply right click at a column and then click on the desired function.
    is this facility also have in sql developer?

    We've kicked around the idea of doing this for awhile. I believe there's already an item in the Exchange if you want to up vote it. The challenge being if it's a result set which hasn't been fully fetched, doing an aggregate would require one - and that could be costly. Of course folks live in the grids so I see the value in this type of feature as well.
    As a workaround, you could of course export your data to CSV or XLS and do the calculations in your favorite spreadsheet software.

  • Group by in a SQL statement

    I have this SQL Statement
    SELECT PTE.PLT_SHORT_NAME PLT_SHORT_NAME,
    COUNT ( * ) SEGMENTS,
    COUNT ( DECODE ( SUBSTR ( TE.EVAL_RESULT , 1 , 1 ) , 'Y' , 1 , NULL ) ) SEGMENTS_COMPLY,
    COUNT ( DECODE ( SUBSTR ( TE.EVAL_RESULT , 1 , 1 ) , 'N' , 1 , NULL ) ) SEGMENTS_NO_COMPLY,
    SUM ( DECODE ( SUBSTR ( TE.EVAL_RESULT , 1 , 1 ) , 'Y' , ( TE.ACTUAL_DURA - ( TE.EXPCT_DURA ) ) , 0 ) ) TIEMPO_GANADO,
    ( ( COUNT ( DECODE ( SUBSTR ( TE.EVAL_RESULT , 1 , 1 ) , 'Y' , 1 , NULL ) ) / COUNT ( * ) ) * 100 ) || '%' COMPLY_PERCENT,
    SUM ( DECODE ( SUBSTR ( TE.EVAL_RESULT , 1 , 1 ) , 'N' , ( TE.ACTUAL_DURA - ( TE.EXPCT_DURA ) ) , 0 ) ) TIEMPO_PERDIDO,
    ( SUM ( DECODE ( SUBSTR ( TE.EVAL_RESULT , 1 , 1 ) , 'Y' , ( TE.ACTUAL_DURA - ( TE.EXPCT_DURA ) ) , 0 ) ) + SUM ( DECODE ( SUBSTR ( TE.EVAL_RESULT , 1 , 1 ) , 'N' , ( TE.ACTUAL_DURA - ( TE.EXPCT_DURA ) ) , 0 ) ) ) DIFERENCIA
    FROM PLT_TRN_EVALS PTE,
    TRN_EVALS TE,
    TRN_EVENT_TIMES_HEADERS TETH
    WHERE ( /* CG$MDTU_QWC_START Q_1.PTE */
    (PTE.PLT_SHORT_NAME IS NOT NULL AND PTE.DELETED = 'N')
    /* CG$MDTU_QWC_END Q_1.PTE */
    ) AND
    ( /* CG$MDTU_QWC_START Q_1.TE */
    (TE.TYP = 'SEG' AND TE.DELETED = 'N')
    /* CG$MDTU_QWC_END Q_1.TE */
    ) AND
    PTE.TE_SEQ = TE.SEQ AND
    ( /* CG$MDTU_QWC_START Q_1.TETH */
    (TETH.DELETED = 'N' AND TETH.SCHED_DATE BETWEEN :P_DATE_FROM AND :P_DATE_TO)
    /* CG$MDTU_QWC_END Q_1.TETH */
    ) AND
    TE.TETH_SEQ = TETH.SEQ
    GROUP BY PTE.PLT_SHORT_NAME
    And I would like to know, how can I include the GROUP BY in order to generate

    I think your question got cut off. What are you trying to generate with this SQL? I should say in advance that Oracle Designer has very few places where you can enter a SELECT command directly. You can usually get it to generate what you need by choosing the correct Table Definition (or View Definition) usages, choosing the display columns you want, and adding WHERE clauses and GROUP BY columns.
    With something as complex as your Statement, I would probably consider creating a View, then use the View in modules.

Maybe you are looking for

  • ITunes not opening when device connected

    About a week ago, iTunes stopped opening when I connected my iPhone.  If I then open iTunes manually, the device will be recognized and will sync.  I checked in the system preferences and my Login Items had iTuneshelper checked, but the icon was a bl

  • Start workflow from DAM-folder

    Hi, is it possible to declare a workflow model so that it is possible to start it by selecting the folder in the DAM rather than the DamAssets? The case is that we would like to add properties to all assets in the selected folder, a variant of the Bu

  • HT1202 Manually Manage Music/ Videos with multiple computers

    I recently got a new iphone 4s and when it was set up I made sure the manually manage music part was on, I added my music and everything worked fine. I'm abroad now and wanted to delete and change some of my music but the manually manage box is no lo

  • Steps to create a Restricted Key Figure

    Hi, I am trying to create a  BEx Query and want to create a Restricted Key Figure. I am using BEx 7.x. Please help me with steps to create a Restricted Key FIgure. Thnaks and Regards, Shreyas Shah

  • Incremental level backup

    If I take incremental level 0 backup on Monday, full database image copy backup on Tuesday, incremental level 1 on Wednesday and Incremental level 2 backup on Thursday; Can i do complete recovery on Friday by applying incremental level 1 & 2 backup o