Get count per each group using t-sql

Hi All, I have a table with 5 columns and my source data looks like this...
ID    Doctor     NurseType    VisitID      Date      
1      Sam       Main-Nurse      10        09/23/2013
1      Tom       Sub-Nurse       10        09/23/2013
1                   Sub-Nurse       10        09/23/2013
2      Ryan      Sub-Nurse       24        10/29/2013
2      Ron       Main-Nurse      24        10/29/2013
3                    Main-Nurse      35        04/12/2014
3                    Main-Nurse      35        04/12/2014
3                    Sub-Nurse       35        04/12/2014
3                     Main-Nurse      40        05/12/2014
3       Greg       Main-Nurse      40        05/12/2014
3                     Sub-Nurse       40        05/12/2014
4       susan     Main-Nurse       45        06/12/2014
4       Roby       Main-Nurse      45        06/12/2014
4                     Sub-Nurse       45        06/12/2014
I want output to be in this format. I want number of doctors present in each ID group per each date using t-sql.
Output:
ID      Comments      VisitID      Date
 1       2 doctors       10        09/23/2013
 2       2 doctors       24        10/29/2013
 3       0 doctor        35        04/12/2014       
 3       1 doctor        40        05/12/2014
 4       1 doctor        45        06/12/2014
Note:
1)NurseType column always will have Main-Nurse and sub-nurse values.Each ID group will have minimum one main and sub-nurses.
2) In the above sample date , Id=3 repeated 2 times becoz visitID and date is different.
3) Also in ID=4(records), even though we have 2 doctors susan and roby we consider them as one doctor becoz NurseType is same(main-nurse).
4) Values in the comments field will always be 2 doctors , 1 doctor and 0 doctor. Rules for populating this column
  a) In a ID group if Main-Nurse and sub-nurse has nay doctors then will show as 2 doctors.
  b) In a ID group if Main-Nurse or sub-nurse (any one) has doctor then will show as 1 doctor.
  c) In a ID group if Main-Nurse and sub-nurse both doesn't have any doctors then will show as 0 doctor
Create statement:
Create table sample  ( ID Int null ,Doctor varchar(25) null,NurseType varchar(20) null ,VisitID int null,Date datetime null)
Insert statement:
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values  (1,'Sam,Main-Nurse' ,  10 ,  '09/23/2013')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values  (1,'Tom,Sub-Nurse'  ,  10 , '09/23/2013')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values  (1, ,'Sub-Nurse'  ,  10 , '09/23/2013')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values  (2,'Ryan','Sub-Nurse'   , 24 ,10/29/2013')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values  (2,'Ron' , 'Main-Nurse' ,     24,'10/29/2013')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values  (3,  , 'Main-Nurse' ,     35  ,'04/12/2014')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values  (3,  ,  'Main-Nurse' ,     35 ,'04/12/2014')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values  (3, ,  'Sub-Nurse' ,      35 ,'04/12/2014')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values  (3,  ,  Main-Nurse',      40  ,'05/12/2014')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values  (3,'Greg', 'Main-Nurse',      40 ,'05/12/2014')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values  (3,  ,  'Sub-Nurse' ,      40,'05/12/2014')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values  (4, 'susan' ,  'Main-Nurse' ,      45,'06/12/2014')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values  (4, 'Roby' ,  'Main-Nurse' ,      45,'06/12/2014')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values  (4,  ,  'sub-Nurse' ,      45,'06/12/2014')
Thanks.
sql

I had to correct the sample script a bit. The query you are asking for comes after the inserts.
Create table sample ( ID Int null ,Doctor varchar(25) null,NurseType varchar(20) null ,VisitID int null,Date datetime null)
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values (1,'Sam','Main-Nurse' , 10 , '09/23/2013')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values (1,'Tom','Sub-Nurse' , 10 , '09/23/2013')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values (1, NULL,'Sub-Nurse' , 10 , '09/23/2013')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values (2,'Ryan','Sub-Nurse' , 24 ,'10/29/2013')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values (2,'Ron' , 'Main-Nurse' , 24,'10/29/2013')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values (3, NULL, 'Main-Nurse' , 35 ,'04/12/2014')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values (3, NULL, 'Main-Nurse' , 35 ,'04/12/2014')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values (3, NULL, 'Sub-Nurse' , 35 ,'04/12/2014')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values (3, NULL, 'Main-Nurse', 40 ,'05/12/2014')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values (3,'Greg', 'Main-Nurse', 40 ,'05/12/2014')
Insert into sample (ID,Doctor,NurseType,VisitID,Date) values (3, NULL , 'Sub-Nurse' , 40,'05/12/2014')
go
SELECT ID, COUNT(Doctor) DoctorCnt, VisitID, Date
FROM sample
GROUP BY ID, VisitID, Date
go
DROP TABLE sample
Erland Sommarskog, SQL Server MVP, [email protected]

Similar Messages

  • GETTING COUNTS FOR EACH SSN

    I am doing a report in ORACLE REPORT WRITER. How can I get counts for each SSN. I want to check the last 7 SSNS
    and if the competence codes are different get a count for them. If the fitness codes are different get a count for them. This is for each SSN. Sometimes SSNS may have different competence codes but the fitness codes are the same. I still need counts for the competence codes. Other times the SSNS have different fitness codes but the competence codes are the same and I need counts for the fitness codes. Other times the fitness codes are different and the competence codes are different and I need counts for the fitness codes and counts for the competence codes. Here is a sample of what the report should look like:
    SSN TOTAL TOTAL
    Competence Fitness
    000000111 13 6
    000000222 6 0
    000000333 0 7
    I have everything wrapped up under one count. I don't know to change the query to display 2 separate counts.
    I have used Summary Columns but that does not work.
    I could use 2 separate querys and get counts for competence and fitness respectively but the SSNS would be out of order. The SSNS must be in order.
    Here is the query.
    SELECT DISTINCT T2.IND_SSN, COUNT(*)cnt1
    FROM (SELECT distinct(t.ind_ssn), t.ind_competence_rtg_old, t.ind_competence_rtg_new, ROW_NUMBER()
    OVER (PARTITION BY t.ind_ssn ORDER BY t.IND_SSN ASC, t.ind_er_per_end_dt DESC) rn
    FROM NCOER_JRNL T) t2
    WHERE t2.rn <= 7
    and (t2.ind_competence_rtg_old <> t2.ind_competence_rtg_new)
    GROUP BY T2.IND_SSN
    UNION
    SELECT DISTINCT T2.IND_SSN, COUNT(*)cnt2
    FROM (SELECT distinct(t.ind_ssn), t.ind_FIT_rtg_old, t.ind_FIT_rtg_new, ROW_NUMBER()
    OVER (PARTITION BY t.ind_ssn ORDER BY t.IND_SSN ASC, t.ind_er_per_end_dt DESC) rn
    FROM NCOER_JRNL T) t2
    WHERE t2.rn <= 7
    and (t2.ind_FIT_rtg_old <> t2.ind_FIT_rtg_new)
    GROUP BY T2.IND_SSN
    ORDER BY 1

    Thanks for you reply Ricardo. It does work (but only if select 1 ticket).
    My bad I only posted one Ticket Number. Actually there are lots of them ( as below). Your code take all the tickets as one tickets.
    TicketNumber
    OwningTeam
    Status
    Date
    Team Number
    123
    TEAM 1
    Pick Up
    11/12/2014
    1
    123
    TEAM 1
    Complete
    11/12/2014
    1
    123
    TEAM 2
    Pick Up
    11/12/2014
    2
    123
    TEAM 2
    Complete
    11/12/2014
    2
    123
    TEAM 2
    Resolve
    11/17/2014
    2
    123
    TEAM 2
    Complete
    11/24/2014
    2
    123
    TEAM 2
    Pick Up
    12/8/2014
    2
    123
    TEAM 2
    Complete
    12/9/2014
    2
    123
    TEAM 2
    Provide Info
    12/17/2014
    2
    123
    TEAM 1
    Pick Up
    1/8/2015
    3
    123
    TEAM 1
    Resoved
    1/8/2015
    3
    456
    TEAM 1
    Pick Up
    11/12/2014
    1
    456
    TEAM 1
    Complete
    11/12/2014
    1
    456
    TEAM 2
    Complete
    11/24/2014
    2
    456
    TEAM 2
    Pick Up
    12/8/2014
    2
    456
    TEAM 2
    Complete
    12/9/2014
    2
    456
    TEAM 3
    Pick Up
    12/17/2014
    3
    456
    TEAM 3
    Working
    12/18/2014
    3
    456
    TEAM 1
    Pick Up
    1/8/2015
    4
    456
    TEAM 1
    Resoved
    1/8/2015
    4
    789
    TEAM 1
    Pick Up
    11/12/2014
    1
    789
    TEAM 1
    Complete
    11/12/2014
    1
    789
    TEAM 2
    Complete
    11/24/2014
    2
    789
    TEAM 2
    Pick Up
    12/8/2014
    2
    789
    TEAM 2
    Complete
    12/9/2014
    2
    789
    TEAM 1
    Complete
    12/12/2014
    3
    Any work around is really appreciated.
    Thanks,
    Rajneet

  • Count() for each group, but only groups having 1+ element like... AND all elements like...

    There are tables(and columns) like:
    'Clients'(clientID)
    'Houses' (houseID)
    'Visits' (clientID, houseID, visit_date)
    'Contracts'(contractID, houseID, clientID, rentDate_from, rentDate_end)
    I have problem with writing MS SQL query of this kind:
    how many visits to houses did each client, before renting one of them?
    Its easy to count total number of Visits for each client, listing all visits + group by clientID and selecting count(*) for each group.
    Lets say this is select_1, and select_2 is listing all Contracts for all clients.
    Select_1 is not answer, because count must be performed only on groups, which:
    -have at least 1 row "like" row in select_2 (it means that at least one of visited houses was rented, because it can happen that client visited few houses, but rented other, not visited house). my idea for this is comparing select_1 and select_2 with:
    "where s1.clientID=s2.clientID and s1.houseID=s2.houseID"
    -each group must have all rows(visits) with date of same day or earlier than contract date
     maybe: "datediff(day, s1.visit_date, s2.rentDate_from) >= 0"

    In future, please provide proper DML, DDL and example data, like I have for you below.
    DECLARE @clients TABLE (clientID INT, name VARCHAR(20))
    INSERT INTO @clients (clientID, name)
    VALUES (1, 'Jonathan'),(2, 'Christopher'),(3, 'James'),(4, 'Jean-Luc'),(5, 'William')
    DECLARE @houses TABLE (houseID INT, address VARCHAR(20))
    INSERT INTO @houses (houseID, address)
    VALUES (1, 'NX01'),(2, 'NCC 1701'),(3, 'NCC 1071A'),(4, 'NCC 1701D'),(5, 'NCC 1701E')
    DECLARE @visits TABLE (clientID INT, houseID INT, visitDateTime DATETIME)
    INSERT INTO @visits (clientID, houseID, visitDateTime)
    VALUES (1,1,'2001-01-01 12:13:14'),
    (2,2,'2001-01-02 12:13:14'),
    (3,2,'2001-01-01 12:13:14'),(3,3,'2001-01-01 12:13:14'),
    (4,4,'2001-01-01 12:13:14'),(4,5,'2001-01-01 12:13:14'),
    (5,4,'2001-01-01 12:13:14'),(5,5,'2001-01-01 12:13:14')
    DECLARE @contracts TABLE (contractID INT IDENTITY, houseID INT, clientID INT, rentStartDate date, rentEndDate date)
    INSERT INTO @contracts (houseID, clientID, rentStartDate, rentEndDate)
    VALUES (1,1,'2001-01-02',NULL),(2,2,'2001-01-02',NULL),(3,3,'2001-01-02',NULL),(4,4,'2001-01-02',NULL),(5,5,'2001-01-02',NULL)
    SELECT contractID, c.houseID, c.clientID, rentStartDate, rentEndDate, cl.clientID, name, h.houseID, address, COUNT(v.clientID) AS visits
    FROM @contracts c
    LEFT OUTER JOIN @clients cl
    ON c.clientID = cl.clientID
    LEFT OUTER JOIN @houses h
    ON c.houseID = h.houseID
    LEFT OUTER JOIN @visits v
    ON c.clientID = v.clientID
    AND c.rentStartDate >= v.visitDateTime
    GROUP BY contractID, c.houseID, c.clientID, rentStartDate, rentEndDate, cl.clientID, name, h.houseID, address

  • Any FM to get count of each week day for the given date range

    Hi guys,
    Any FM to get count of each week day for the given date range?
    eg: If i give 14/07/2008 to 14/08/2008
    I need to find how many Mondays, tuesdays...sundays in this given date range.
    If not single FM is available, any logic that gives above result is also appreciated.
    Thanks,
    Vinod.

    hi Vinod,
    this is not a full solution, I just give you a basic idea:
    DATA : lv_start TYPE sy-datum VALUE '20080714',
           lv_end   TYPE sy-datum VALUE '20080814'.
    WHILE lv_start LE lv_end.
      CALL FUNCTION 'FTR_DAY_GET_TEXT'
        EXPORTING
          pi_date = lv_start.
    * IMPORTING
    *   PE_DAY_TEXT1       =
    *   PE_DAY_TEXT2       =
    *   PE_DAY             =
    * you have to summarize the output here somehow...
      lv_start = lv_start + 1.
    ENDWHILE.
    hope this helps
    ec

  • Cannot get Oracle sequence to be used with SQL Loader direct path load.

    I attempted to load approximately 3 million rows from a flat file into a 10g database using SQL Loader direct path load. In order to generate a primary key for each of these rows I used a simple SQL expression which gets the next number of an Oracle sequence and assigned that to my primary key column inside the control file. The strange thing is no primary key was generated for each of these columns as I see the sequence was not advanced. Furthermore when I try to run a query to find the count on those rows which have this column as NOT NULL ,I get the total of all the rows even though on inspection this column is empty in each of the rows.
    As far as I know, in the control file for a direct path load I am able to use a SQL Expression that returns simple scalar data which a NEXTVAL on a sequence does. (Oreilly Oracle SQL Loader The Definitive Guide p.184)
    Does anybody why my primary key was not generated and furthermore why is this column in a query appear to be NOT NULL when in fact it has nothing in it?

    Daniel,
    I appreciate your response alot.
    Now a follow on. You say that SQL*Loader is the fastest way to get data into Oracle Spatial even though the conventional path. How does SQL*Loader do this? Doesn't it use OCI?
    I just can't help but think that coverting my data to SQL*Loader format, and then having it parse it and send it to the database in some form must be slower than me just sending whatever SQL Loader sends to the DB myself using OCI. Am I missing something?
    The SQL Loader documentation seems to suggest that SQL*Loader just turns the input into alot of INSERT stateemnts. If so, can't I just do this?
    My performance with OCI and INSERT statements isn't very good, but I believe I am doing one transaction per insert. Might I be as well off to concentrate on fine tuning my OCI based code using INSERTs?
    I will actually do some time tests myself, but I would appreciate your opinion.
    Once again thanks for the great info you have provided.

  • Always on Availability groups using static SQL Tcp Port

    Hi,  I have 2 SQL 2012 servers in my DMZ and I have assigned SQL to run on a static TCP Port.  I would like to setup Always On availability groups on the servers but I cannot get the failover to work with the static TCP port.  It works fine
    with dynamic ports.
    When the failover is initiated it attempts to connect to the secondary replica with out using the static port,  can someone tell me how to setup the availability group using static tcp ports.
    Thanks,

    When I setup the secondary replica I added the port number, but it doesn't appear to use it for failover.  I add the secondary replica w/o errors.
    I am not sure how to add the port number to the primary.
    Dave
    Hi Dave,
    Based on your description, could you please post the error message when getting failover to the secondary replica?
    In addition, If you use the default port of 1433 for availability group listener VNNs, you will still need to ensure that no other services on the cluster node are using this port; otherwise this would cause a port conflict.
    If one of the instances of SQL Server is already listening on TCP port 1433 via the instance listener and there are no other services (including additional instances of SQL Server) on the computer listening on port 1433, this will not cause a port conflict
    with the availability group listener. However multiple instances of SQL Server (side-by-side)should not be configured to listen on the same port.
    For more details, please review this article:
    Availability Group Listeners, Client Connectivity, and Application Failover (SQL Server).
    Thanks,
    Lydia Zhang

  • Getting the max count for each group

    Hi, I am a newbie and working on a project for school. I have been working this problem for a couple of days and made a bit of progress.
    I have two tables, student and enroll for a college database. I need to show the students who have the most enrollments in each major. So far, I have:
    WITH COUNT_Q AS
    SELECT B.SSN, B.MAJOR, COUNT (A.CLASS_NO) AS COUNTCLASS
    FROM ENROLL A, STUDENT B
    WHERE A.SSN = B.SSN
    GROUP BY B.SSN, B.MAJOR
    SELECT MAX(COUNTCLASS), MAJOR
    FROM COUNT_Q
    GROUP BY MAJOR
    I am getting the correct results but need to show the SSN and Major of the studens. When I add in the SSN and Major, like below, I get back too many records.
    WITH COUNT_Q AS
    SELECT B.NAME, B.SSN, B.MAJOR, COUNT(A.SSN) AS COUNTCLASS
    FROM ENROLL A, STUDENT B
    WHERE A.SSN = B.SSN
    GROUP BY B.NAME, B.SSN, B.MAJOR
    SELECT *
    FROM COUNT_Q
    WHERE (COUNTCLASS) IN (SELECT MAX(COUNTCLASS)
    FROM COUNT_Q
    GROUP BY MAJOR
    Can someone help point me in the right direction?

    SELECT  B.NAME,
            B.SSN,
            B.MAJOR
      FROM  (
             SELECT  B.NAME,
                     B.SSN,
                     B.MAJOR,
                     COUNT(A.CLASS_NO) SSN_MAJOR_COUNTCLASS
                     DENSE_RANK() OVER(PARTITION BY MAJOR ORDER BY COUNT(A.CLASS_NO) DESC) RNK
               FROM  ENROLL A,
                     STUDENT B
               WHERE A.SSN = B.SSN
               GROUP BY B.NAME,
                        B.SSN,
                        B.MAJOR
      WHERE RNK = 1
    /SY.
    Edited by: Solomon Yakobson on Mar 27, 2011 6:53 PM

  • How to get summary on each group

    Hello,
    I have DB9i and I have this query
    select nvl(max(gl.load_mw), 0) MaxLoad, g.grid_name as GridName, g.max_capacity as MaxCapacity, to_char(gl.r_date,'dd/mm/rrrr') as RDate, to_char(gl.r_time,'00') as RTime
    from grid g, grid_load gl
    where to_char(gl.r_date,'mmyyyy') = '012008'
    group by  r_date,grid_name, max_capacity,   r_timeI want the max of load on each GridName but with the above query its not possible if I do group with the above query the result will be same as simple query because of the existence of date and time in query. Is there any other way to handle this situation.
    Thanks and Regards, Khawar
    Message was edited by:
    S. Khawar

    If i have undersood correctly... you do not want to group by date/time ... whereas you want to display the date/time values.....
    I do this using the emp table of the SCOTT schema... with analytic function.....
    You have a query like this(no analytic function)
    SQL> select max(sal) , job , hiredate from emp
      2  group by job , hiredate;
      MAX(SAL) JOB       HIREDATE
          1600 SALESMAN  20/02/1981
          1250 SALESMAN  28/09/1981
          1500 SALESMAN  08/09/1981
          3000 ANALYST   03/12/1981
          1100 CLERK     23/05/1987
           950 CLERK     03/12/1981
           799 CLERK     17/12/1980
          2850 MANAGER   01/05/1981
          5000 PRESIDENT 17/11/1981
          1250 SALESMAN  22/02/1981
          2450 MANAGER   09/06/1981
          2975 MANAGER   02/04/1981
          3000 ANALYST   19/04/1987
          1310 CLERK     23/01/1982
    14 rows selected
    You can use this with the analytic function:
    SQL> select max(sal) over(partition by job,hiredate) , job , hiredate from emp;
    MAX(SAL)OVER(PARTITIONBYJOB,HI JOB       HIREDATE
                              3000 ANALYST   03/12/1981
                              3000 ANALYST   19/04/1987
                               799 CLERK     17/12/1980
                               950 CLERK     03/12/1981
                              1310 CLERK     23/01/1982
                              1100 CLERK     23/05/1987
                              2975 MANAGER   02/04/1981
                              2850 MANAGER   01/05/1981
                              2450 MANAGER   09/06/1981
                              5000 PRESIDENT 17/11/1981
                              1600 SALESMAN  20/02/1981
                              1250 SALESMAN  22/02/1981
                              1500 SALESMAN  08/09/1981
                              1250 SALESMAN  28/09/1981
    14 rows selectedGreetings...
    Sim

  • CSM per admin group using per device group

    I am looking to see if multiple admin and device groups can be created to limit certain administrators to administrate only certain devices but not others.
    For example:
    admin group "ag_na" (including user admin1 & admin2)  can make changes to device group "dg_na" containing (device 1, device 2) only
    admin group "ag_ca" (including user admin3 & admin4) can make changes to device group "dg_ca" containing (device30 & device31) only
    Any tips on if / how to do this?
    Thanks

    You can do it by integrating the CSM into an ACS v4.2 and doing RBAC. There you can define for which NDGs a user has which access policy.
    http://www.cisco.com/en/US/docs/security/security_management/cisco_security_manager/security_manager/4.1/installation/guide/aduser.html#wp1063220
    Unfortunately this is a short-therm solution as ACS v4.2 has been put to EoS and no real alternative methods are available today. Hopefully Cisco will come up with a new solution on the long-therm.

  • Statistics under each group

    Hi, Background: I am querying a table which gives me a list of every people manager in the organization and their direct reports. I am able to do this because of a couple of fields, namely EmpID and MgrID. I loop through each level in the heirarchy and it spits out a list of employees for that manager. It works well and does what I want it to do. The lists that are produced show the employee's first and lastname and Completion date. If there is a date in the completion date column then that means that the employee completed the online course that is mandatory throughout the company.
    My question is this. How can I get statistics under each group? For example, under each group I would like to list the following: Total number of employees within the group, number of employees completing the course, and finally the completion rate which is number of completions divided by total number in group. Thank you very much. I have attached my code in a cfm file.

    Hi,
    Use the SQL aggregate functions,
    http://www.sql-tutorial.com/sql-aggregate-functions-sql-tutorial/
    And if you want to have your statistics as a graphical representation, you can use CF's <cfchart> tag,
    http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_c_05.html
    HTH

  • SQL Query for getting Row No for each group

    Dear Oracle Gurus,
    I want to allocate Rownum to each group. How we can do this with single SQL. Help me on this.
    Thanks

    select deptno, ename, row_number() over (partition by deptno order by ename) from emp order by 1,3;

  • Sum of LineCount Including Groups and Detail Data On Each Page Used To Generate New Page If TotalPageLineCount 28

    Post Author: tadj188#
    CA Forum: Formula
    Needed: Sum of LineCount Including Groups and Detail Data On Each Page Used To Generate New Page If TotalPageLineCount > 28
    Background:
    1) Report SQL is created with unions to have detail lines continue on a page, until it reaches page footer or report footer, rather than using  subreports.    A subreport report is now essentially a group1a, group1b, etc. (containing column headers and other data within the the report    with their respective detail lines).  I had multiple subreports and each subreport became one union.
    Created and tested, already:
    1) I have calculated @TotalLineForEachOfTheSameGroup, now I need to sum of the individual same group totals to get the total line count on a page.
    Issue:
    1) I need this to create break on a certain line before, it dribbles in to a pre-printed area.
    Other Ideas Appreciated:
    1) Groups/detail lines break inconveniently(dribble) into the pre-printed area, looking for alternatives for above situation.
    Thank you.
    Tadj

    export all image of each page try like this
    var myDoc = app.activeDocument;
    var myFolder = myDoc.filePath;
    var myImage = myDoc.allGraphics;
    for (var i=0; myImage.length>i; i++){
        app.select(myImage[i]);
        var MyImageNmae  = myImage[i].itemLink.name;
        app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.high;
        app.jpegExportPreferences.exportResolution = 300;
           app.selection[0].exportFile(ExportFormat.JPG, File(myFolder+"/"+MyImageNmae+".JPEG"), false);
        alert(myImage[i].itemLink.name)

  • Get the Count for each row

    I'm trying to get the count for each row to total count for each month
    Something like this
    Hardware     |      Jan
    Monitors       |       5
    Processors   |      137
    Printers        |      57
    etc........
    How can I write a query for this. I can get the Hardware column but don't know how to get the next column.

    If you can provide more data like sample input DML statements it would have been wonderful..
    Assuming is , you need a pivot. Here is an article on basic Pivot..
    http://sqlsaga.com/sql-server/how-to-use-pivot-to-transform-rows-into-columns-in-sql-server/
    something like this may be..
    DECLARE @Input TABLE
    Hardware VARCHAR(20),
    [Date] VARCHAR(20)
    INSERT INTO @Input VALUES('Monitor', '01/01/2014'), ('CPU', '01/01/2014'), ('Monitor', '01/03/2014')
    , ('ABC', '01/01/2014'),('Monitor', '02/01/2014')
    ;WITH CTE AS
    SELECT Hardware, LEFT(DATENAME(M, [Date]),3) AS [MonthName] FROM @Input
    SELECT *
    FROM
    SELECT Hardware, [MonthName], COUNT(Hardware) AS Count FROM CTE GROUP BY Hardware, [MonthName]) a
    PIVOT (MAX([Count]) FOR [MonthName] IN ([Jan], [Feb])) pvt
    Please mark as answer, if this has helped you solve the issue.
    Good Luck :) .. visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.

  • Getting the first row for each group

    Hi Everyone,
    I have a query which returns a number of rows, all of which are valid. What I need to do is to get the first row for each group and work with those records.
    For example ...
    client flight startairport destairport stops
    A fl123 LGW BKK 2
    A fl124 LHR BKK 5
    B fl432 LGW XYZ 7
    B fl432 MAN ABC 8
    .... etc.
    I would need to return one row for Client A and one row for Client B (etc.) but find that I can't use the MIN function because it would return the MIN value for each column (i.e. mix up the rows). I also can use the rownum=1 because this would only return one row rather than one row per group (i.e. per client).
    I have been investigating and most postings seem to say that it needs a second query to look up the first row for each grouping. This is a solution which would not really be practical because my query is already quite complex and incorporating duplicate subqueries would just make the whole thing much to cumbersome.
    So what I really new is a "MIN by group" or a "TOP by group" or a "ROWNUM=1 by group" function.
    Can anyone help me with this? I'm sure that there must be a command to handle this.
    Regards and any thanks,
    Alan Searle
    Cologne, Germany

    Something like this:
    select *
    from (
       select table1.*
       row_number() over (partition by col1, col2 order by col3, col4) rn
       from table1
    where rn = 1In the "partition by" clause you place what you normally would "group by".
    In the "order by" clause you define which will have row_number = 1.
    Edit:
    PS. The [url http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions004.htm#i81407]docs have more examples on using analytical functions ;-)
    Edited by: Kim Berg Hansen on Sep 16, 2011 10:46 AM

  • Use of SQL Profiles where each schema has very different data distribution and volumes

    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0      Production
    TNS for Linux: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    Our architecture has multiple client schemas in the same database. Each schema has the same code base (tables, procedures etc) but each client's data is very different in terms of volumes and skew/distribution per table. This architecture was done based on cost - I know it's not ideal but it can't change.....
    I am fairly seasoned with performance management and so know the usual tricks of when to eat up the table using parallel full table scans etc. I couldn't further optimise a given stmt for our largest table. I'll call it TSPCI and it has monthly partitions (2 years) and totals about 35Gb in the largest client schema.
    Anyway, I was surprised when ADDM suggested that I could achieve 98% improvement if I were to use a given SQL Profile. Great?
    So, here's my issue - I've found that the same SQL_ID is shared across all those different client schemas: I can't see how to get it to pick/use the SQL Profile in only a particular client schema - let's call it NEX - and not in another (lets call it COL).
    If I generate a SQL Profile as NEX, has it analysed and built the SQL Profile based on the NEX schema and is it therefore invalid/undesirable to have that SQL Profile used in the COL schema??
    I suppose that I could add a small change (say /*+ NEX */) to the SQL in the NEX schema to make the given sql unique there and then generate a SQL Profile for that..........
    What am I missing here?

    Well, I can confirm the behaviour: accept a SQL Profile for a given SQL in one schema and verified that it is used in another schema (where the data volume and distribution is very different).
    I can also confirm the workaround - simply add a hint to the SQL to make it unique such that I could use different sql profiles for the otherwise exact same sql in different schemas.
    I'm happy enough with this workaround but I'll leave this thread unanswered in case someone can suggest a better approach.

Maybe you are looking for

  • Itunes wont say my ipod is connected when i plug it in HELP!

    I need BIG help I've tryed everything but i can't find out whats wrong. When i plug my ipod in to my computer all it does is charge it doesnt up load or say that its pluged in. I WANT MY NEW SONGS ON MY IPOD I WANT TO NO WHATS GOING ON. CAN SOMEONE P

  • New Feature for proxy

    Hi all! I'm not found this feature in current Async OS documentation for web products. So propose new feature - extended user logging mode. In this mode all POST requests with posted data from some user group are grabbed and inserted into database fo

  • IBook G4 and iPhoto

    I'm still having problems importing images into iPhoto it keeps closing within 2-3 images..(I'm importing from file transfered from intel imac)..L

  • Copy BLOB column  to filesystem

    Hello everybody. Im working with RedHat Linux and Oracle Database 10gR2. My problem , I have some tables with Blob columns those Blob columns have pictures (jpg, gif etc) , and I need copy those pics ,blob colums, to filesystem. Question : Can anybod

  • Hewlett Packard Elite Display E271i LED Blacklit Monitor _flickerin

    Dear HP Team, I have a new Hewlett Packard Elite Display E271i LED Blacklit Monitor. It is plugged via HDMI cable and a Mini Video Port adapter to my mac book pro _ Version Mac OSX 10.7.5. This is now already the 2nd monitor I got, the first one had