Count certain rows more than once

I have the sql below:
select count(*), ind_encounter
from (
select x.sak_recip, x.dte_first_svc, x.ind_encounter
from t_tmp x
group by x.sak_recip, x.dte_first_svc, x.ind_encounter
union all
select x.sak_recip, x.dte_first_svc, x.ind_encounter
from t_tmp x
where x.sak_procedure in (1, 2, 3, 4) )
group by ind_encounter
What I need to do is count the sql in bold more than once. If one row in the table has sak_procedure = 1, I want to count that row 13 times. I know that if union 11 more sqls, I will count those 13 times.
I would like to know if someone knows an easer way.
thanks for your help

try
select count(*), ind_encounter,
         sum(cnt1) -- your counter
  from (select x.sak_recip, x.dte_first_svc, x.ind_encounter, count(*) * N cnt1
          from t_tmp x
         group by x.sak_recip, x.dte_first_svc, x.ind_encounter
        union all
        select x.sak_recip, x.dte_first_svc, x.ind_encounter, count(*) * M cnt1
          from t_tmp x
         where x.sak_procedure in (1, 2, 3, 4)
        group by x.sak_recip, x.dte_first_svc, x.ind_encounter
         group by ind_encounterEdited by: AlexAnd on Dec 4, 2011 11:21 PM

Similar Messages

  • How do I repeat the same row more than once in report 10g

    How do I repeat the same row more than once in report 10g
    So I can print the bar code more than once
    in report;
    Edited by: user11106555 on May 9, 2009 5:50 AM

    GREAT THAN X MAN
    It is already working, but with the first ROW
    select ename from emp
    CONNECT BY ROWNUM<=5
    ENAME
    SMITH
    SMITH
    SMITH
    SMITH
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    BUT I want this result
    Item1
    Item2
    Item3
    to
    Item1
    Item1
    Item1
    Item2
    Item2
    Item2
    Item3
    Item3
    Item3

  • Update Trigger Assistance - Update Same Row More than Once?

    Good morning,
    I'm new to Triggers and am not understanding why this is not working.  I've tried the web and none of the articles seem to answer my question.  What I'm trying to do is clean a string and standardize some data the users input into a 1000 character
    varchar field.  I have a source table which has a trigger on it that inserts a limited number of columns that we'll use for reporting purposes.  After the row has been inserted into the table (referred to as "destination" in the code block),
    I'm looking to update the comments string, capitalizing the first character of the string, standardizing spacing after a colon, removing hyphens at the beginning of the string.  The source and destination tables both have the comments field as a varchar
    1000, not null data type with a key id between the source and destination tables.  At another segment of our system, there were errors reporting nulls and when this was removed, everything cleared up.  I can do a series of replace statements when
    the data is required in reports but would rather have it clean in the destination table.  The code is below:
    CREATE TRIGGER [dbo].[destination_Update_trg]
    ON [dbo].[destination]
    AFTER UPDATE
    AS
    BEGIN
    SET NOCOUNT ON;
    IF EXISTS (SELECT *
    FROM destination C
    JOIN INSERTED I
    ON I.PrimaryKeyID = C.PrimaryKey
    WHERE I.Comments IS NOT NULL AND I.Comments <> '')
    BEGIN
    UPDATE T
    SET T.Comments =
    CASE
    WHEN T.Comments <> '' AND LEFT(CAST(T.Comments AS VARCHAR (1000)), 2) LIKE '- %'
    THEN SUBSTRING(T.Comments, 3, 1000)
    END
    FROM destination T
    JOIN INSERTED I
    ON T.primarykey = I.primarykey
    WHERE T.primarykey = I.primarykey
    UPDATE T
    SET T.Comments = UPPER(LEFT(CAST(T.Comments AS VARCHAR (1000)), 1)) + SUBSTRING(CAST(T.Comments AS VARCHAR (1000)), 2, 1000)
    FROM destination T
    JOIN INSERTED I
    ON T.primarykey = I.primarykey
    WHERE T.primarykey = I.primarykey
    UPDATE T
    SET T.Comments = REPLACE(SUBSTRING(T.Comments, 1, 1000), ': ', ': ')-- '[A-9]: [A-9]'
    FROM destination T
    JOIN INSERTED I
    ON T.primarykey = I.primarykey
    WHERE T.primarykey = I.primarykey
    AND SUBSTRING(T.Comments, 1, 1000) LIKE '%[A-Z]%: [A-Z]%'
    END
    RETURN
    END;
    GO
    Perhaps there's a better way to accomplish the task. I appreciate your review and assistance. Thank you.

    First, the trigger only fires when you do an UPDATE.  I'm not sure from your description whether or not you are expecting this trigger to fire when you do an insert on dbo.destination.  If you want it to fire on INSERTs, then you need to specify
    FOR INSERT (or FOR INSERT, UPDATE if you want it to fire on both inserts and updates).
    More importantly, the first update in your trigger does
    SET T.Comments =
    CASE
    WHEN T.Comments <> '' AND LEFT(CAST(T.Comments AS VARCHAR (1000)), 2) LIKE '- %' THEN SUBSTRING(T.Comments, 3, 1000)
    END
    When you do a CASE and you don't have an ELSE clause, there is an implicit ELSE NULL clause added.  So your update is equivalent to
    SET T.Comments =
    CASE
    WHEN T.Comments <> '' AND LEFT(CAST(T.Comments AS VARCHAR (1000)), 2) LIKE '- %' THEN SUBSTRING(T.Comments, 3, 1000)
    ELSE NULL
    END
    So your very first update sets the Comments column to NULL in every row that was updated where the Comments column is not like '- %'.  You want to change the case statement to be
    SET T.Comments =
    CASE
    WHEN T.Comments <> '' AND LEFT(CAST(T.Comments AS VARCHAR (1000)), 2) LIKE '- %' THEN SUBSTRING(T.Comments, 3, 1000)
    ELSE T.Comments
    END
    (Or you can put the test in the where clause so that you only update those rows where the Comments column is like '- %'.  That would look like
    UPDATE T
    SET T.Comments = SUBSTRING(T.Comments, 3, 1000)
    END
    FROM destination T
    JOIN INSERTED I
    ON T.primarykey = I.primarykey
    WHERE LEFT(CAST(T.Comments AS VARCHAR (1000)), 2) LIKE '- %'
    (Note that you do not need to include the T.Comments <> '' because if T.Comments is Like '- %', then it cannot be the empty string and you do not need to include WHERE T.primarykey = I.primarykey because you know that is true since you did an inner
    join on T.primarykey = I.primarykey.
    Tom

  • -setFence:count: called more than once per transaction

    I am getting following error, any body have any idea what it is?
    -setFence:count: called more than once per transaction
    Debugger stopped.
    Program exited with status value:101.
    Thanks in Advance
    Ravi

    I am getting the same error...
    T'is usly a m'ry error.
    Use the debugging/testing tools in the latest Xcode to track down suspects, etc.

  • Using firefox 5 - when ever I try to use the same key more than once in a row, it does not work. Hitting the multiple times does nothing at all. How can this be corrected. HELP!!!

    everything that needs to be done on the keyboard is effected - letters, numbers, backspace, directionals, delete, home, end, page up, page down, '''all keys that are pressed more than once''' It does not matter what webpage I am on.
    PLEASE HELP
    this is very frustrating

    You may have switched on an accessibility feature called FilterKeys by keeping the Shift key pressed for too long.
    * http://www.microsoft.com/enable/products/windowsxp/default.aspx
    *http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/access_filterkeys_turnon.mspx?mfr=true

  • Performance... Why a function column in a view is executed more than once...?

    Why a function column created inside a view is executed more than once when called more than once?
    EXAMPLE:
    create or replace view aux1 as
    date_column,
    any_function(date_column) column1
    from any_table
    create or replace view aux2 as
    column1 c1,
    column1 c2,
    column1 c3
    from aux1
    select * from aux2
    It will execute 3 times the function any_function... logically the value will be the same for all columns...
    I understand why!... are 3 calls... but...
    Why not to create a "small" verification and if the function column was execute replace the second, the third... value? ... instead of execute 3, 4... times...
    tks
    Braga

    Actually, this is more than a performance issue. This is a consistency problem. If the function is NOT deterministic then you may get different values for each call which is clearly not consistent with selecting 3 copies of the same column from a row. Oracle appears to have fixed this in 9i...
    Connected to:
    Oracle8i Enterprise Edition Release 8.1.7.2.0 - Production
    With the Partitioning option
    JServer Release 8.1.7.2.0 - Production
    create view v1 as select dbms_random.value(1,100) r from dual;
    create view v2 as select r r1, r r2 from v1;
    select * from v2;
              R1           R2
              93           74
    Connected to:
    Oracle9i Enterprise Edition Release 9.0.1.3.0 - Production
    With the Partitioning option
    JServer Release 9.0.1.3.0 - Production
    create view v1 as select dbms_random.value(1,100) r from dual;
    create view v2 as select r r1, r r2 from v1;
    select * from v2;
              R1           R2
              78           78Richard

  • Button/click box click more than once

    Hi, I'm hoping you guys can point out what I'm doing wrong...
    I have an image where the user can click on certain parts of
    it to display a callout. However, I want them to be able to click
    on the area of the image more than once if requried. I suppose you
    can say it's a bit like an image map.
    First I used click boxes to achieve this, then I tried using
    transparent buttons. However for both of these methods you can only
    click on each part once during playback. Clicking again does not
    show the callout.
    I thought about copying the contents to another slide and add
    a 'Reset' button the user could click on. This would move to the
    other slide, but this seems a bit on the 'clunky' side, so I
    thought there must be a setting or something really obvious that I
    have missed. I was unable to find the relevant informaiton in the
    help file or elsewhere in the forum, so if it does exist I would
    appreciate someone pointing me in the right direction.
    How can I allow the user to click on parts of the image more
    than once to show the callout?
    Thanks for your help,
    Liz

    Thanks for your reply Rick.
    I started the activity using rollovers, but I wanted the user
    to do something more definite than just hovering over each part of
    the image. So essentially, I want the rollover functionality but
    with the ability to click instead of just hovering the cursor over.
    I thought this would be easy!
    I've tried using both buttons and click boxes without any
    success. I ventured a little into slidelets, but I want the callout
    to appear in a very specific place and this did not appear to
    satisfy my requirements. The 'click to stick' sounds intriguing so
    I'll take a look into this, but I'm not convinced it's what I want.
    Any more suggestions are most welcome.
    Regards
    Liz

  • How to call the same query more than once with different selection criteria

    Hi,
    Please do anybody know how to solve this issue? I need to call one query with the fixed structure more than once with different selection criteria. For example. I have following data
    Sales organization XX
                         Income 2008  Income 2009
    Customer A       10                 20
    Customer B        30                  0
    Sales organization YY
                         Income 2008  Income 2009
    Customer A        20                5
    Customer B        50                10
    Now, I need this. At the selection screen of query, user fill variable  charakteristic "Sales organization" with interval  XX - YY, than I need to generate two separate results per sales organization, one for Sales Organization XX and the second for SO YYwhich will be displayed each on separate page, where result for SO YY will be dispayed under result for SO YY. Are there some options how to do it for example in Report Designer or WAD or with programming? In Report Designer is possible to use one query more than once, but I dont know how to force each query in RD to display result only for one Sales Organization, which will be defined in selection screen.
    Thank you very much
    J.

    Hello,
    thanks to all for cooperation. Finally we solved this issue with the following way..
    User fill appropriate SO on the selection screen, which is defined as range. This will resulte, that selected SO are listed in report below each othe (standard behavior). Required solution we achieved with the Report Designer, we set page break under each Result row of RD. This caused, that report is divided into required part per SO, which are stated each on separate page.
    J.

  • Is it possible to open a form created with screen painter more than once?

    I have created a form with the screen painter. In the screen painter the form is assigned a FormUID. Probably because this is done, it is impossible to open the form more than once??
    Thanks,
    Kind regards

    Hi J.
    The answer is yes You just have to give your form a unique id.
    1) Give your form in screen painter a name like BTWO_DYNAMIC_UID (just plain text).
    2) Make sure your <i>FormType</i> and <i>appformnumber</i> have a unique number (i.e. 2000060001). You can do this in the xml source.
    3) By loading your document replace the BTWO_DYNAMIC_UID with an unique id. I have a counter that's a member of my class and increase that number to get a unique id (BTWO_F_1, BTWO_F_2 etc)
    I have added a code sample, SBOApplication is my SAP application object and mFormNumber is a member (integer) of my class.
    <i>Succes d'r mee, en als 't nie lukt hoor ik het wel... ;)</i>
    <b>Code (C#):</b>
    // New xml document
    XmlDocument oXmlDoc = new XmlDocument();
    private Form LoadUniqueForm(string AMyFile)
      // Define your path to
      sPath = @"Forms" + AMyFile;
      // Load the form
      oXmlDoc.Load(sPath);
      // Replace the string with an unique id
      mFormNumber++;
      string sXML = oXmlDoc.InnerXml.Replace("BTWO_DYNAMIC_UID", "BTWO_F_" + mFormNumber.ToString());
      // load the XML file in SAP
      SBOApplication.LoadBatchActions(ref sXML);
      // Return the form
      return SBOApplication.Forms.Item("BTWO_F_" + mFormNumber.ToString());

  • Duplicate entries / Employee is appearing twice in report (OR more than onc

    Duplicate entries / Employee is appearing twice in report (OR more than once)
    When I hire an employee, I assign the position, and based on the positions other values get defaulted /assigned to that employee.
    I have one case where employee has been assigned to one position, but with different position descriptions, and in report it is showing duplicate entries for the same personnel number, now client need for one personnel number only one row to display in report
    Also I tries to run , Birthday list standard report , it is also showing 2 entries (Or sometime more than 2)for the same personnel number , May I know why this is happening?
    And how to fix this bug
    Thanks and Regards
    Jaydeep Jadhav

    Hi,
    Can you check where the code is written to get employees from position, there may be two cases where multiple records exists for single person.
    1) When getting data for pernr assigning to a position they may missed out date condition. If so we need to bring only active positions assigned to that employee.
    2) There may be multiple positions assigned to a single person. In this case you need to ask the client what you need to do.
    Delete adjacent duplicate is may  not be correct solution as which position we need to delete is not sure. You check above two cases and go head.
    Hope this information will help you.
    Regards,
    Narendra.Soma

  • Report to select customer ID occuring more than once

    My report requirement is to capture transaction detail when a customer ID occurs more than once. Is there a way to do a sum count on the customer id in order to display the transaction detail. My current solution is to run a report where the customer count is greater than one, and then do a subquery against that data to display the transaction detail. I would like to be able to eliminate the subquery.

    Hi,
    You can create an analytic function to count the customer_ID per every transaction:
    count(customer_id) over (partition by ..<enter the fields of the report>.....)
    This will give for every transaction the number of transaction per same customer_id
    Now that you have it you can create a condition on it so
    that you will get only transaction with count customer_id > 1

  • Business rules in 11.1.1.3 execute more than once

    My client has the situation where certain business rules (launched from the Planning BR interface) will execute more than once, sometimes twice or even three times. It seems that the rule will start to execute and then after 1 or two minutes, will launch again. the job console will show the information.

    This is a known issue and has to do with the http timeout settings. Usually this will happen on the 5 minute limit, but it depends what setting they have.
    Take a look at this article and see if it applies:
    Business Rules That Take More Than Five Minutes to Execute Are Re-launched Repeatedly [ID 755406.1]
    Agnete
    Edited by: Agnete on Oct 22, 2012 12:51 PM

  • Trigger firing more than once

    Can any one help me i am having the problem with trigger . The trigger fires more than once. I want the trigger to be fired for every COMMIT and not for each row.
    The pl/sql used for populating the table in given below
    CREATE OR REPLACE TRIGGER REFRESH_MV_TRIGGER
    AFTER INSERT OR UPDATE ON CONTACT_HISTORY
    DECLARE
    cnt NUMBER;
    BEGIN
    IF ( INSERTING ) THEN
    dbms_output.put_line('INSERTING');
    END IF;
    IF ( UPDATING ) THEN
    dbms_output.put_line('UPDATING');
    END IF;
    END;
    DECLARE
    BEGIN
    FOR i IN 1..2 LOOP
    INSERT INTO CONTACT_HISTORY(TARGET_ID,CAMPCODE,COMMSTAGE,CUSTOMER_KEY,solicit_dt)
    VALUES(i,'CAMP4','COMM1',i,SYSDATE);
    END LOOP;
    COMMIT;
    END;
    sql> output when i run pl/sql block
    INSERTING
    INSERTING

    I am not shure what you need exactly but maybe this might help:
    CREATE TABLE dept (
      deptno NUMBER(2) PRIMARY KEY,
      dname  VARCHAR2(14),
      loc    VARCHAR2(13)
    CREATE TABLE dept_history (
      deptno NUMBER(2),
      dname  VARCHAR2(14),
      loc    VARCHAR2(13)
    CREATE MATERIALIZED VIEW dept_mv
      BUILD IMMEDIATE
      REFRESH ON COMMIT
      AS SELECT * FROM dept
    CREATE OR REPLACE TRIGGER bir_dept_mv
      BEFORE INSERT ON dept_mv
      FOR EACH ROW
    BEGIN
      INSERT INTO dept_history VALUES (:NEW.deptno, :NEW.dname, :NEW.loc);
    END;
    INSERT INTO DEPT (deptno, dname, loc) VALUES (1, 'D1', 'L1');
    1 row created.
    INSERT INTO DEPT (deptno, dname, loc) VALUES (2, 'D2', 'L2');
    1 row created.
    SELECT * FROM dept;
        DEPTNO DNAME          LOC
             1 D1             L1
             2 D2             L2
    SELECT * FROM dept_history;
    no rows selected
    SELECT * FROM dept_mv;
    no rows selected
    COMMIT;
    Commit complete.
    SELECT * FROM dept_history;
        DEPTNO DNAME          LOC
             1 D1             L1
             2 D2             L2
    SELECT * FROM dept_mv;
        DEPTNO DNAME          LOC
             1 D1             L1
             2 D2             L2Regards,
    Zlatko Sirotic

  • Displaying the records records which are coming more than once

    hi
    create table temp(comp_id int,branch_id int);
    comp_id | branch_id
    ---------+-----------
    1000 | 1
    1000 | 1
    1000 | 2
    1000 | 2
    1000 | 3
    2000 | 1
    2000 | 1
    2000 | 2
    2000 | 3
    how can i write a query which displays the records records which are coming more than once on the basis of fields comp_id and branch_id. e.g. 1000 | 1 should be displayed because it is coming more than once. 1000 | 3 should not be, because it has a single entry.

    select comp_id, branch_id, count(*)
    from temp
    group by comp_id, branch_id
    having count(*)>1
    Please note this forum is not a SQL class and it is not the place to have your homework done.
    Sybrand Bakker
    Senior Oracle DBA

  • In migrating to a 21.3" iMac from a Time Machine backup, can I do this more than once?

    In migrating to a 21.3" iMac from a Time Machine backup, can I do this more than once?

    David,
    My apologies....I was working on questions from a different thread and thought yours was part of that one.  Your question is fine where it is....
    Now....that being said, I'm afraid I don't know the answer to your question.  I know you can exclude certain items from being backed up in Time Machine, which would save disk space on your external drive. But, you'd first have to calculate how much disk space you're using for the different things you want to back up vs. those you want to exclude.
    I think it MIGHT be possible to do what you want, but (in my honest opinion) it's a recipe for a LOT of headaches should things not work out as you calculated. Better (again, in my opinion) to just pick up a larger external hard drive and transfer everything as Time Machine was designed.
    Just my $0.02 worth.

Maybe you are looking for

  • Help with Lightbox and adding images

    Tutorials show me that I should select the blue icon and insert images. In the tutorial I see this OPTIONS panel then the add images option. But when I click the blue button, in every template and new muse document I've tried. I see this - Compositio

  • Digital av cord

    I recently got a digital av cord to use with my IPad2, which I am still waiting for... Anyways... The cord say compatible with Iphone4 as well, but when I plug in into my TV and hook up with an HDMI cable, I am only getting sound on my tv, but no pic

  • SAN Snapshots

    Does anyone know if SAN snapshot technology can be used with Oracle Databases The 10gR2 Backup and Recovery Advanced User Guide seems to have a chapter ( CH17 ) that covers User Managed Backups which I am guessing where SAN snapshot technology would

  • Bat file for running scheduled jobs

    Hi I am not entirely sure whether this is the correct forum to post this question, so apologies if I have posted this question in the wrong place. Anyhow, I would like to know how to create two automated bat file scripts that will execute a PL/SQL pa

  • Safari opens, but there is no window

    This just started happening all of a sudden. overnight actually, i went to sleep w/ safari still open and when i came back the window was gone. I tried restarting the computer, shutting down completely, and repair permissions, but no luck. I can clic