Help on group by statement

I have a table with four columns. I want to select rows if the status is different and the firstname and lastname are same. How do I achieve this.
For ex: select firstname,lastname,status,sum(amt)
from table a
group by 1,2,3
Thank you,

Hi,
create table test
(firstname varchar2(20),
lastname varchar2(20),
status char(1),
salary number
insert into test values('John','Boughr','1','100');
insert into test values('John','Boughr','0','200');
insert into test values('doug','smiti','1','300');
insert into test values('doug','smiti','0','400');
insert into test values('aaa','Boughr','1','100');
insert into test values('aaa','Boughr','1','100');
insert into test values('bbbb','Boughr','1','100');
select a.firstname,a.lastname, sum(a.salary)
from test a
where a.firstname||a.lastname
in (select b.firstname||b.lastname
from test b
where a.status <> b.status
group by a.firstname,a.lastname
having count(*) > 1
FIRSTNAME LASTNAME SUM(A.SALARY)
John Boughr 300
doug smiti 700
SQL>

Similar Messages

  • Any hints on what may be wrong with this GROUP BY statement?

    Hi,
    I am testing the code below suggested on this site. When I tried it code and during my CHECK, and it gets to the GROUP BY line, and jumps back to the SELECT statement with the following message (even though DATE2 is in the GROUP BY statement):
    E:The field "/BIC/AODSSSS00~DATE2" from the SELECT list is is
    missing in the GROUP BY clause. is missing in the GROUP BY clause. Is
    missing in the GROUP BY clause. is missing in the GROUP BY clause. is
    I have played around, changing DATE2 in the GROUP By line with /BIC/AODSSSS00~DATE2 or /BIC/AODSSSS00-DATE2 or /BIC/DATE2, but still I get likewise.
    loop at RESULT_PACKAGE into wa_RESULT_PACKAGE.
    SELECT NUM ITEM /BIC/DATE1 DATE2 sum( QTY ) as QTY
    INTO corresponding fields of table it_TABLE1
    FROM /BIC/AODSSSS00
    where /BIC/DATE1 <= wa_RESULT_PACKAGE-DATE2
    AND NUM = wa_RESULT_PACKAGE-NUM
    AND ITEM = wa_RESULT_PACKAGE-ITEM
    GROUP BY NUM ITEM /BIC/DATE1 DATE2.
    wa_RESULT_PACKAGE-/BIC/AONTIMQTY = sum.
    MODIFY RESULT_PACKAGE from wa_RESULT_PACKAGE.
    Endloop.
    Thanks

    I am not totally clear on what you want to achieve.  But please look this code over and see if it is closer to what you want to do.
    I changed your workarea to a field-symbol, which are a little more convenient to use.  <result_fields> is already defined for you in your end routine.
    I used tables and fields that exist in our system, but you should be able to translate those back to your system.
    Please let me know if you need more help.
    LOOP AT result_package ASSIGNING <result_fields>.
      SELECT me_order_n me_itemno serv_date SUM( /bic/znosubasp ) AS /bic/znosubasp
      INTO CORRESPONDING FIELDS OF it_table1
      FROM /bic/azmord2d00
      WHERE serv_date <= wa_result_package-serv_date
      AND me_order_n = wa_result_package-me_order_n
      AND me_itemno = wa_result_package-me_itemno
      GROUP BY me_order_n me_itemno serv_date.
        <result_fields>-me_quanti = it_table1-/bic/znosubasp.
      ENDSELECT.
    ENDLOOP.

  • Need help in group left report

    i need help in group left report
    i am making group left report in which all group data on top is repeating as many time as detail record is .
    for axampel
    if
    group record:
    fielda fieldb field c
    fielda fieldb field c
    fielda fieldb field c
    fielda fieldb field c
    detail record :
    fieldd fielde feildf
    fieldd fielde feild
    fieldd fielde feild
    fieldd fielde feildf
    how i can show group record on top once and on each group record show detail record belong to master record.
    plz help me
    A.R

    I think you Should go for Group above report...
    and if you want group left only and also want to display master once then
    put all master fields above but yeah take care of it's master repeting frame
    it should not change...
    and if you want i can send you an example...
    Enjoy Oracle...

  • How to create a Module Component containing a MAX().. GROUP BY Statement

    Hi
    What do I have to do, to get a module component, which, in the end, returns a statement like
    SELECT mas_id, mas_name
    FROM v_masken_zugriff
    WHERE mzu_datenbank = 'database'
    AND (UPPER(vur_name) = UPPER(user)
    OR UPPER(vur_name) IN (SELECT granted_role
    FROM dba_role_privs
    WHERE UPPER(grantee) =UPPER( user)
    GROUP BY mas_id, mas_name
    i.e. how do I generate a GROUP BY Statement?
    Thanks a lot!
    Karine

    Where are you trying to place this?
    Is this a LOV or a pl/sql?

  • Need help with the session state value items.

    I need help with the session state value items.
    Trigger is created (on After delete, insert action) on table A.
    When insert in table B at least one row, then trigger update value to 'Y'
    in table A.
    When delete all rows from a table B,, then trigger update value to 'N'
    in table A.
    In detail report changes are visible, but the trigger replacement value is not set in session value.
    How can I implement this?

    You'll have to create a process which runs after your database update process that does a query and loads the result into your page item.
    For example
    SELECT YN_COLUMN
    FROM My_TABLE
    INTO My_Page_Item
    WHERE Key_value = My_Page_Item_Holding_Key_ValueThe DML process will only return key values after updating, such as an ID primary key updated by a sequence in a trigger.
    If the value is showing in a report, make sure the report refreshes on reload of the page.
    Edited by: Bob37 on Dec 6, 2011 10:36 AM

  • Looking for some help with building insert statements...

    Hi, I am using some sql to build some insert statements for me to update a set of tables in our qa environments. The scripts that I have created were working great until someone added a column to some of the tables in the qa env which in turn makes my scripts break because I was simply building the statment to do someting like this...
    insert into dest_table (select * from source_table@dblink);
    But now when the coumns in the tables do not match it breaks...
    This is the dynamic create script I use, can anyone help or suggest a better way to be able to build update statements update to qa tables when the columns are mismatched?
    spool insert.sql
    select
    'insert into ' || table_name || ' (select * from ' || table_name || '@prod );' || chr(10) || ' commit;'
    from user_tables
    where table_name in
    (select * from refresh_tablesl)
    any help is greatly appreciated,
    Thanks.

    See my reply to your duplicate post
    looking for help building dynamic insert statements...

  • GROUP BY statement problem due to a version update

    Hello:
    Recently, I updated B.Objects XI R2 from SP2 to SP5 and I stumbled with some problems. The biggest one is that the SQL View inside SQL Editor doesn't show GROUP BY statement when Autogenerated SQL radio button is activated. For example:
    SELECT
    VMINROAQ_VMOCMTDQ.OCMT_DS_OPERADOR_CMT,
    VMSIQ9.VMINROAQ.OCMT_CO_OPERADOR_CMT,
    VMSIQ9.VMINROAQ.PRES_NU_PRESEL_P5,
    VMSIQ9.VMINROAQ.FECH_NU_ANNO,
    VMSIQ9.VMINROAQ.FECH_NU_MES,
    VMSIQ9.VMINROAQ.INRO_CA_LINEAS_RECLAMADAS,
    VMSIQ9.VMFECHDQ.FECH_NO_MES,
    VMSIQ9.VMINROAQ.INRO_CA_TIEMPO_MEDIO_RESOL
    FROM
    VMSIQ9.VMINROAQ,
    VMSIQ9.VMOCMTDQ  VMINROAQ_VMOCMTDQ,
    VMSIQ9.VMFECHDQ
    WHERE
    ( VMSIQ9.VMINROAQ.OCMT_CO_OPERADOR_CMT=VMINROAQ_VMOCMTDQ.OCMT_CO_OPERADOR_CMT  )
    AND  ( VMSIQ9.VMINROAQ.FECH_NU_MES=VMSIQ9.VMFECHDQ.FECH_NU_MES and VMSIQ9.VMINROAQ.FECH_NU_ANNO=VMSIQ9.VMFECHDQ.FECH_NU_ANNO  )
    AND
    VMSIQ9.VMFECHDQ.FECH_NO_MES  =  'Diciembre'
    AND
    VMSIQ9.VMINROAQ.FECH_NU_ANNO  =  2009
    *GROUP BY VMINROAQ_VMOCMTDQ.OCMT_DS_OPERADOR_CMT,*
    VMSIQ9.VMINROAQ.OCMT_CO_OPERADOR_CMT,
    VMSIQ9.VMINROAQ.PRES_NU_PRESEL_P5,
    VMSIQ9.VMINROAQ.FECH_NU_ANNO,
    VMSIQ9.VMINROAQ.FECH_NU_MES,
    VMSIQ9.VMINROAQ.INRO_CA_LINEAS_RECLAMADAS,
    VMSIQ9.VMFECHDQ.FECH_NO_MES,
    +VMSIQ9.VMINROAQ.INRO_CA_TIEMPO_MEDIO_RESOL+
    (Bold words only appear in SP2, not in SP5.)
    With this problem I have incongruities in my new reports, but it's odd that reports made with SP2 maintain the same old structure with SP5.
    A solution is to check "personalize SQL" radio button, but I can't use it because my client demands it. So, does anyone know why B.O. does this? Even more, does anyone know a trick or a way to solve this problem?
    I hope your news. Kind regards.
    José María.

    Hi,
    Is this problem for only one report or no.of reports. If it is for a no. of reports  then the universe on which these reports are bulid i.e in universe parameters -> options (last tab) -> there some parameters related to grouby clause
    Try to enable them and check it reporting level.
    Cheers,
    Suresh Aluri.

  • Help with this update statement..

    Hi everyone,
    I am trying to update a column in a table .I need to update that column
    with a function that takes patient_nbr and type_x column values as a parameter.
    That table has almost "300,000" records. It is taking long time to complete
    almost 60 min to 90 min.
    Is it usual to take that much time to update that many records?
    I dont know why it is taking this much time.Please help with this update statement.
    select get_partner_id(SUBSTR(patient_nbr,1,9),type_x) partner_id from test_load;
    (it is just taking 20 - 30 sec)
    I am sure that it is not the problem with my function.
    I tried the following update and merge statements .Please correct me if i am wrong
    in the syntax and give me some suggestions how can i make the update statement fast.
    update test_load set partner_id = get_partner_id(SUBSTR(patient_nbr,1,9),type_x);
    merge into test_load a
    using (select patient_nbr,type_x from test_load) b
    on (a.patient_nbr = b.patient_nbr)
    when matched
    then
    update
    set a.partner_id = get_partner_id(SUBSTR(b.patient_nbr,1,9),b.type_x);
    there is a index on patient_nbr column
    and the statistics are gathered on this table.

    Hi Justin,
    As requested here are the explain plans for my update statements.Please correct if i am doing anything wrong.
    update test_load set partner_id = get_partner_id(SUBSTR(patient_nbr,1,9),type_x);
    "PLAN_TABLE_OUTPUT"
    "Plan hash value: 3793814442"
    "| Id  | Operation          | Name             | Rows  | Bytes | Cost (%CPU)| Time     |"
    "|   0 | UPDATE STATEMENT   |                  |   274K|  4552K|  1488   (1)| 00:00:18 |"
    "|   1 |  UPDATE            |        TEST_LOAD |       |       |            |          |"
    "|   2 |   TABLE ACCESS FULL|        TEST_LOAD |   274K|  4552K|  1488   (1)| 00:00:18 |"
    merge into test_load a
    using (select patient_nbr,type_x from test_load) b
    on (a.patient_nbr = b.patient_nbr)
    when matched
    then
    update
    set a.partner_id = get_partner_id(SUBSTR(b.patient_nbr,1,9),b.type_x);
    "PLAN_TABLE_OUTPUT"
    "Plan hash value: 1188928691"
    "| Id  | Operation            | Name             | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |"
    "|   0 | MERGE STATEMENT      |                  |   274K|  3213K|       |  6660   (1)| 00:01:20 |"
    "|   1 |  MERGE               |        TEST_LOAD |       |       |       |            |          |"
    "|   2 |   VIEW               |                  |       |       |       |            |          |"
    "|*  3 |    HASH JOIN         |                  |   274K|    43M|  7232K|  6660   (1)| 00:01:20 |"
    "|   4 |     TABLE ACCESS FULL|        TEST_LOAD |   274K|  4017K|       |  1482   (1)| 00:00:18 |"
    "|   5 |     TABLE ACCESS FULL|        TEST_LOAD |   274K|    40M|       |  1496   (2)| 00:00:18 |"
    "Predicate Information (identified by operation id):"
    "   3 - access("A"."patient_nbr"="patient_nbr")"Please give some suggestions..
    what's the best approach for doing the updates for huge tables?
    Thanks

  • Can anyone help me understand "Continue Statements"?

    Hi,
    I was wondering if anyone could help me understand continue statements. I've been studying the java tutorials this weekend but can not get my head around the following explanation: (My thoughts are at the end of this message and it might be easiest to read them first!)
    "The continue statement skips the current iteration of a for, while , or do-while loop. The unlabeled form skips to the end of the innermost loop's body and evaluates the boolean expression that controls the loop. The following program, ContinueDemo , steps through a String, counting the occurences of the letter "p". If the current character is not a p, the continue statement skips the rest of the loop and proceeds to the next character. If it is a "p", the program increments the letter count.
    {code}class ContinueDemo {
    public static void main(String[] args) {
    String searchMe = "peter piper picked a peck of pickled peppers";
    int max = searchMe.length();
    int numPs = 0;
    for (int i = 0; i < max; i++) {
    //interested only in p's
    if (searchMe.charAt(i) != 'p')
    continue;
    //process p's
    numPs++;
    System.out.println("Found " + numPs + " p's in the string.");
    }{code}
    Here is the output of this program:
    Found 9 p's in the string.
    To see this effect more clearly, try removing the continue statement and recompiling. When you run the program again, the count will be wrong, saying that it found 35 p's instead of 9.
    A labeled continue statement skips the current iteration of an outer loop marked with the given label. The following example program, ContinueWithLabelDemo, uses nested loops to search for a substring within another string. Two nested loops are required: one to iterate over the substring and one to iterate over the string being searched. The following program, ContinueWithLabelDemo, uses the labeled form of continue to skip an iteration in the outer loop.
    {code}class ContinueWithLabelDemo {
    public static void main(String[] args) {
    String searchMe = "Look for a substring in me";
    String substring = "sub";
    boolean foundIt = false;
    int max = searchMe.length() - substring.length();
    test:
    for (int i = 0; i <= max; i++) {
    int n = substring.length();
    int j = i;
    int k = 0;
    while (n-- != 0) {
    if (searchMe.charAt(j++)
    != substring.charAt(k++)) {
    continue test;
    foundIt = true;
    break test;
    System.out.println(foundIt ? "Found it" :
    "Didn't find it");
    }{code}
    Here is the output from this program.
    Found it"
    Here are Woodie's thoughts........................................
    1) With the first program I don't understand how the program counts the number of "p's". Like for example how it stores the number of "p's". Shouldn't it say:
    if (searchMe.charAt(i) = 'p') then store it in some sort of containers??? 2) With the second program, I don't understand the test section. For example: Why does it have --? why does it have != after while and why does it have != after if?
    while (n-- != 0)
                    if (searchMe.charAt(j++) != substring.charAt(k++))
                        continue test;
                foundIt = true;
                     break test;Edited by: woodie_woodpeck on Nov 23, 2008 3:29 AM

    Woodie, I think they're just silly "theoretical" examples... ergo don't worry too much not understanding them, coz they don't actually make a lot of sense... as you've allready pointed out there are other "more normal" control structures which achieve the same thing, and which in this case (in my humble opinion) would make for clearer, more concise, more maintainable code.
    All you need to know about continue is "it means go back to the top of the loop"... If you're not comfortable using "continue" then don't.
    There's more than one way to do it.
      public static void main(String[] args) {
        try {
          final String s = "peter piper picked a peck of pickled peppers";
          int count = 0;
          for ( char c : s.toStringArray() ) {
            if (c=='p') count++;
          System.out.println("There are "+count+ " p's in '"+s+"'");
        } catch (Exception e) {
          e.printStackTrace();
      }Having said all that... I did use continue in anger the other day... I was reading Geometries from a shape file... the reader was throwing an ArrayIndexOutOfBoundsException given an "empty Feature" (ie a feature with the geospatial presence)... All I did was catch the exception and continue trying to read the new feature... the alternative would have been to rewrite the control logic of the whole reader loop... quick, simple effective... but I don't routinely build continue statements into new code... just a matter of personal taste.
    Cheers. Keith.

  • Help with Group By on SQL statement

    Iu2019m trying to group by Item Code in the following query, however, I keep receiving the following error message.  Do you know why?
    Msg 306, Level 16, State 2, Line 1
    The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.
    SELECT            dbo.OQUT.DocNum,
                      dbo.OQUT.U_UDF_3 AS QuoteNumber,
                      dbo.OQUT.U_QuoteDesc,
                      dbo.OQUT.U_RevQuote,
                      dbo.OQUT.U_RevDate,
                      dbo.OQUT.DocDate,
                      dbo.OQUT.DocDueDate,
                      dbo.OQUT.U_ReqDate,
                      dbo.OQUT.U_DueDate,
                      dbo.OQUT.CardCode,
                      dbo.OQUT.CardName,
                      dbo.OQUT.CntctCode,
                      dbo.QUT1.LineNum,
                      dbo.QUT1.BaseLine,
                      dbo.QUT1.ItemCode,
                      dbo.QUT1.Dscription,
                      SUM(dbo.QUT1.Quantity),
                      SUM(dbo.QUT1.OpenQty),
                      SUM(dbo.QUT1.U_Original_Qty),
                      dbo.QUT1.U_LeadTime,
                      dbo.QUT1.Price,
                      SUM(dbo.QUT1.LineTotal),
                      dbo.QUT1.unitMsr AS SalUnitMsr,
                      dbo.QUT1.U_UDF_12 AS PNQuoted,
                      dbo.QUT1.U_UDF_13 AS MFRQuoted,
                      dbo.QUT1.U_UDF_16 AS MinQty,
                      dbo.QUT1.U_UDF_17 AS MultiQty,
                      dbo.TBC_AMLPriority1.U_Mfg_Name,
                      dbo.TBC_AMLPriority1.U_Mfg_PN,
                      dbo.QUT1.U_Parent,
                      dbo.ITT1.Quantity AS BOMQty,
                      dbo.OCPR.Name
    FROM         dbo.OQUT INNER JOIN
                      dbo.QUT1 ON dbo.OQUT.DocEntry = dbo.QUT1.DocEntry LEFT OUTER JOIN
                        dbo.OCPR ON dbo.OQUT.CntctCode = dbo.OCPR.CntctCode LEFT OUTER JOIN
    dbo.ITT1 ON dbo.QUT1.ItemCode = dbo.ITT1.Code AND dbo.QUT1.U_Parent =
    dbo.ITT1.Father LEFT OUTER JOIN
                      dbo.TBC_AMLPriority1 ON dbo.QUT1.ItemCode = dbo.TBC_AMLPriority1.U_ItemCode
    WHERE     (dbo.QUT1.Quantity > 0)and dbo.OQUT.DocNum='1'
    GROUP BY    dbo.QUT1.ItemCode,
                dbo.OQUT.DocNum,
                dbo.OQUT.U_UDF_3

    Dear,
    As per your message you mentioned that u r getting following error "
    The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator."
    The error is due to group by of a field whose type is text,ntext.....
    if it is text or ntext just replace that field
    Convert(varchar(100),fieldName)...
    Hope it will help you....
    Regards
    Sanjay

  • I need some help about Group by sql statement.

    Thank you for reading my post
    I am learning more sql and i have a question which is about HR schem.
    how i can show Departments.department_name in the following sql query?
    I want query to show department names along with department IDs.
    SELECT department_id dept_id, job_id, SUM(salary)
    FROM employees
    GROUP BY department_id, job_id ;thanks

    hi
    like this
    SQL> ed
    Wrote file afiedt.buf
      1  select d.department_id dept_id, d.department_name, e.job_id, sum(e.salary)
      2  from employees e, departments d
      3  where e.department_id = d.department_id
      4* group by d.department_id, d.department_name, e.job_id
    SQL> /
       DEPT_ID DEPARTMENT_NAME                JOB_ID     SUM(E.SALARY)
            10 Administration                 AD_ASST             4400
            20 Marketing                      MK_MAN             13000
            20 Marketing                      MK_REP              6000
            30 Purchasing                     PU_MAN             11000
            30 Purchasing                     PU_CLERK           13900
            40 Human Resources                HR_REP              6500
            50 Shipping                       ST_MAN             36400
            50 Shipping                       SH_CLERK           64300
            50 Shipping                       ST_CLERK           55700
            60 IT                             IT_PROG            28800
            70 Public Relations               PR_REP             10000
       DEPT_ID DEPARTMENT_NAME                JOB_ID     SUM(E.SALARY)
            80 Sales                          SA_MAN             61000
            80 Sales                          SA_REP            243500
            90 Executive                      AD_VP              34000
            90 Executive                      AD_PRES            24000
           100 Finance                        FI_MGR             12000
           100 Finance                        FI_ACCOUNT         39600
           110 Accounting                     AC_MGR             12000
           110 Accounting                     AC_ACCOUNT          8300
    19 rows selected.
    SQL>hope this helps
    Taj

  • Help needed in MERGE statement

    Hi,
    I am new to PL/SQL, I want to update a table called "final_test" based on the below query result.
    1. I want to check whether that particular record is present or not in my "final_test" table.
    2. If its present in the "final_test" table and the process_status got changed then I want to update that alone in my "final_test" table.
    3. If its not present then I want to insert that record into my "final_test" table.
    Basically I am retrieving the report and its status for a particular date.
    select
    b.id,
    a.name,
    a.t_name,
    c.process_status,
    c.time_process
    from rep_tab_map a, j_tab_map b, proc_status c
    where a.t_name=b.t_name
    and b.id=c.id (+)
    and trunc(c.date_start)=trunc(sysdate -1)
    group by a.name,b.id,c.process_status,c.time_process,a.t_name
    order by 2
    I thought of using Merge statement but i am not sure what i have to use in ":USING" and "ON" clause.
    Please help me with MERGE or with someother way.
    Thanks

    Assuming final_test has same structure as select list in your query:
    merge
      into final_test a
      using (
             select  b.id,
                     a.name,
                     a.t_name,
                     c.process_status,
                     c.time_process
               from  rep_tab_map a,
                     j_tab_map b,
                     proc_status c
               where a.t_name=b.t_name
                 and b.id=c.id(+)
                 and trunc(c.date_start)=trunc(sysdate -1)
               group by a.name,b.id,c.process_status,c.time_process,a.t_name
            ) b
      on (b.id = a.id)
      when matched then update set a.name = case a.process_status
                                              when b.process_status then a.name
                                              else b.name
                                            end,
                                   a.t_name = case a.process_status
                                                when b.process_status then a.t_name
                                                else b.t_name
                                              end,
                                   a.process_status = b.process_status,
                                   a.time_process = case a.process_status
                                                      when b.process_status then a.time_process
                                                      else b.time_process
                                                    end
      when not matched then insert(
                                   a.id,
                                   a.name,
                                   a.t_name,
                                   a.process_status,
                                   a.time_process
                            values(
                                   b.id,
                                   b.name,
                                   b.t_name,
                                   b.process_status,
                                   b.time_process
    /SY.

  • How to handle comments in group financial statement

    We have a situation in project where we need to manage comments about organizations financial statement item.
    We are going to use the SAP BCS 6.0 version as a product.
    Please note we can consider any tool like BPC or SSM or anything else if supporting our requirement well.
    We already identified couple of options but we still want to explore and welcome new ideas & experience.
    By now some people might have understood, what I am looking for but below example is for those who never got chance to work in finance but similar kind of situation     
    In the above example comment explain more about the report which may change time to time or in some places it may give explanation about the figures or assessment of a group
    So we are looking for following u2013
    1.     A tool or way to enter comment below the report.
    2.     But there are different groups who enter their comment based on the explanation or assessment submitted by the previous group.
    3.     Meaning approval Process after group u2018Au2019 approver approve then only it goes to Group u2018Bu2019.
    4.     Roll Forward prior period comments at input level
    5.     Submit and Lock comments from lower level to the next level
    6.     Roll up Comments to Assessment
    7.     Lock & Unlock Commentary
    8.     Commentary Review Report.
    9.     It should be stored by time meaning history of the comment should be maintained.
    Kindly please let me know if you have any question or call me if you need more explanation.
    Please note we are open to consider all kind of experience and ideas. So please write if something pop up in your mind.
    Thanks in advance
    Edited by: SMP on Jun 18, 2010 11:03 AM
    Edited by: SMP on Jun 18, 2010 11:05 AM

    Hi SMP,
    I had quite the same need in my last SEM-BCS project.
    Our conclusion was that SEM-BCS was not enough flexible to deal with comments. Indeed, the system performs "integrity checks" when posting transactions.
    Hope it helps
    Regards,
    Thibaud

  • Help with group by

    Can anyone tell why this query isn't working? It returns NOT a group by expression error. It has something to do with the subquery but I know I can't group by the alias of that statement. Any help would be appreciated.
    SELECT acc.uprn,
    NVL (SUM (lth.balance), 0) balance,
    (SELECT SUM (balance)
    FROM lsc_transaction_history lth
    WHERE acc.account_no = lth.account_no
    AND SUBSTR (lth.account_no,10,3) = 450) repair_balance
    FROM lsc_occupants occ,
    lsc_account acc,
    lsc_area lmc,
    hpm_view_property p,
    lsc_account_parties_view accn,
    lsc_transaction_history lth
    WHERE occ.seq_no = acc.seq_no
    AND acc.uprn = occ.uprn
    AND occ.account_type = acc.account_type
    AND lmc.code = acc.area_code
    AND p.uprn = occ.uprn
    AND accn.account_no = acc.account_no
    AND lth.account_no = acc.account_no
    GROUP BY acc.uprn

    Well, the hints were already given, but maybe an example make it clearer.
    SQL> create table lsc_account
      2  as
      3  select 1 uprn, '100000000000' account_no from dual union all
      4  select 1, '100000000450' from dual union all
      5  select 2, '100000000450' from dual
      6  /
    Tabel is aangemaakt.
    SQL> create table lsc_transaction_history
      2  as
      3  select '100000000000' account_no, 100 balance from dual union all
      4  select '100000000000', 200 from dual union all
      5  select '100000000000', 300 from dual union all
      6  select '100000000450', 400 from dual union all
      7  select '100000000450', 500 from dual
      8  /
    Tabel is aangemaakt.
    SQL> SELECT acc.uprn
      2       , NVL (SUM (lth.balance), 0) balance
      3       , ( SELECT SUM (balance)
      4             FROM lsc_transaction_history lth
      5            WHERE acc.account_no = lth.account_no
      6              AND SUBSTR (lth.account_no,10,3) = 450
      7         ) repair_balance
      8    FROM lsc_account acc
      9       , lsc_transaction_history lth
    10   WHERE lth.account_no = acc.account_no
    11   GROUP BY acc.uprn
    12  /
              WHERE acc.account_no = lth.account_no
    FOUT in regel 5:
    .ORA-00979: Geen GROUP BY-uitdrukking.
    SQL> select acc.uprn
      2       , nvl(sum(lth.balance),0) balance
      3       , nvl(sum(case substr(lth.account_no,10,3) when '450' then balance end),0) repair_balance
      4    from lsc_account acc
      5       , lsc_transaction_history lth
      6   where lth.account_no = acc.account_no
      7   group by acc.uprn
      8  /
    UPRN      BALANCE REPAIR_BALANCE
       1         1500            900
       2          900            900You only need to access the lsc_transaction_history table once this way.
    Regards,
    Rob.

  • Help with grouping similar lines

    Hi,
    could you help me with one sql query in Oracle 11g.
    I have data with two columns - timestamp, counter
    4.7.2012 10:01, 13
    4.7.2012 10:03, 0
    4.7.2012 10:04, 0
    4.7.2012 10:05, 0
    4.7.2012 10:21, 3
    4.7.2012 10:33, 0
    4.7.2012 10:51, 6
    What I need to get is to group lines with counter = 0 which are next to each other and keep the info about start and end of the timestamp.
    so first I need to use rank
    line_number, timestamp, counter, rank
    1, 4.7.2012 10:01, 13, 0
    2, 4.7.2012 10:03, 0, 1
    3, 4.7.2012 10:04, 0, 2
    4, 4.7.2012 10:05, 0, 3
    5, 4.7.2012 10:21, 3, 0
    6, 4.7.2012 10:33, 0, 0
    7, 4.7.2012 10:51, 6, 0
    and then group lines 2, 3, 4 into one line, because line's counter=0 and there is more then one line in the group.
    so the result would be
    4.7.2012 10:01, 13
    4.7.2012 10:03 - 4.7.2012 10:05, 0
    4.7.2012 10:21, 3
    4.7.2012 10:33, 0
    4.7.2012 10:51, 6
    Thanks a lot for any ideas,
    D.
    Edited by: dusoo on Jul 11, 2012 6:37 AM

    Hi,
    You can do something like this:
    WITH     got_grp     AS
         SELECT     tmstmp, counter
         ,     ROW_NUMBER () OVER ( ORDER BY      tmstmp)
              -  ROW_NUMBER () OVER ( PARTITION BY  counter
                                        ORDER BY          tmstmp
                           )     AS grp
         FROM    table_x
    --     WHERE     ...     -- If you need any filtering, do it here
    SELECT       MIN (tmstmp) || CASE        -- You'll probably want to use TO_CHAR here, and 2 lines below
                                  WHEN  COUNT (*) > 1
                         THEN '-' || MAX (tmstmp)
                              END
    ,         counter
    FROM       got_grp
    GROUP BY  counter, grp
    ORDER BY  MIN (tmstmp)
    ;TIMESTAMP is a keyword in Oracle 9 (and up), so it's not a good column name. I used TMSTMP instead.
    This assumes that tmstmp is unique. If not, you'll have to add something to the analytic ORDER BY clauses.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data. For example, what defines a "group" in this problem? It seems to be consectuive rows (in order by tmstmp), but what else? Will all members of a gropup have the same value for counter, regardless of the difference in tmstmp? (That's what I assumed above.) Will all members of a group have tmstmp within 1 minute of another, regardless of counter?
    Always say which version of Oracle you're using.
    See the forum FAQ {message:id=9360002}

Maybe you are looking for

  • CALL TRANSACTION VK13 AND SKIP FIRST SCREEN

    Hi, I'm using ALV report and i want to call the the Tcode VK13 from alv and skip the screens. I have declared form user_command and calling from the "REUSE_ALV_LIST_DISPLAY". The actual issue is how to select the radio button in the pop up window and

  • My itunes u crashes every time i try to switch to the library.

    My itunes u crashes every time i try to switch to the library. It automatically opens one course everytime i go in, but when i try to flick back to the library page it crashes. This has only been since i upgraded my ipad mini to the new operating sys

  • I use to be able to go back several sites by clicking on a down arrow next to the back button. Where's it gone in Firefox 4?

    I realise you can click on history but if you have more than one tab open, it combines all these in the history sequence. The lack of this list of previously visited sites within the tab accessible by the down arrow is extemely frustrating. How can t

  • Crystal Reports monthly revenue calculation

    Hy I would like to create a cross tab from B1 data sources to show the monthly revenue. I use SBO 8.8 and CR 2008. My problem is that I don't know exatly how the SBO is calculating on the sales analysis. Normaly is working like this: (oinv.doctotal-o

  • Crystal 2008 with BDS 2006

    Post Author: DiegoBrazil CA Forum: Other Hi.... nowaday we are using CRPE32.dll to integrate Delphi with Crystal 8.5. But, we are having problems with RTF format (problems with Special Characters). We are migrating Crystal 8.5 to Crystal 2008, but we