Pls. help on my query!!!

hi to all i have a query but i am getting the ff: error
Error starting at line 1 in command:
select max(dateadd) as newdate, startseries from transactions where transid = 'RS'
Error at Command Line:1 Column:32
Error report:
SQL Error: ORA-00937: not a single-group group function
and my query is to get the ff: data of course (2 columns)
select max(dateadd) as newdate, startseries from transactions where transid = 'RS'
if this wont work is there any possible solution? i tried using subqueries and still not giving me any data to display...
thanks!

hi to all:
this is my table details (sql developer tool)
REM ERA_DB RSMASTER
CREATE TABLE "ERA_DB"."RSMASTER"
(     "RSNO" NUMBER NOT NULL ENABLE,
     "RSDATE" DATE,
     "EMPID" VARCHAR2(4 BYTE),
     "CATEGORYID" NUMBER,
     "DOCREF" VARCHAR2(30 BYTE),
     "NOTE" VARCHAR2(255 BYTE),
     CONSTRAINT "RS_PK" PRIMARY KEY ("RSNO") ENABLE,
     CONSTRAINT "RSMASTER_UK1" UNIQUE ("DOCREF", "RSDATE") ENABLE
REM ERA_DB RSMASTER_UK1
CREATE UNIQUE INDEX "ERA_DB"."RSMASTER_UK1" ON "ERA_DB"."RSMASTER" ("DOCREF", "RSDATE")
REM ERA_DB RSMASTER_INDEX1
CREATE INDEX "ERA_DB"."RSMASTER_INDEX1" ON "ERA_DB"."RSMASTER" ("EMPID", "CATEGORYID")
REM ERA_DB TRANSACTIONS
CREATE TABLE "ERA_DB"."TRANSACTIONS"
(     "AUTOID" NUMBER NOT NULL ENABLE,
     "TRANSID" VARCHAR2(2 BYTE) NOT NULL ENABLE,
     "DATEADD" DATE,
     "TRANSNAME" VARCHAR2(20 BYTE) NOT NULL ENABLE,
     "STARTSERIES" NUMBER NOT NULL ENABLE,
     "ENDSERIES" NUMBER NOT NULL ENABLE,
     CONSTRAINT "TRANSACTIONS_PK" PRIMARY KEY ("AUTOID") ENABLE
REM ERA_DB TR_TRANSAUTOID
CREATE OR REPLACE TRIGGER "ERA_DB"."TR_TRANSAUTOID"
before insert
on transactions
for each row
WHEN (new.autoid is null) begin
select sq_transautoid.nextval into :new.autoid from dual;
end;
ALTER TRIGGER "ERA_DB"."TR_TRANSAUTOID" ENABLE;
TRANSACTIONS is my table where i save all kinds of transaction type (e.g. Purchased Orders, Delivered Orders so on...) these includes the series of its invoices/receipts... in other words, for example the series ends e.g. 2000-4000 i need to enter another series (that's why i do have a date when it was just entered to strictly monitor my series being issued) so i need to get the latest series collection using max(dateadd) that's why that row will be updated once i use the function max() to know which is the latest... the update that i am calling thru stored proc so that my data part is truly separated w/ php with an oop approach...
i dont knw if this is clear enough guys, but again thank you for all your help! inform me if i need to make another clarifications... thank you so much sirs!!! :)

Similar Messages

  • Pls help in this query

    Hi,
    I've needed to print output like below. pls help me out .
    Thanks & Regards,
    Ramana.

    SQL> select '*****'||chr(10)||'****'||chr(10)||'***'||chr(10)||'**'||chr(10)||'*' from dual;
    '*****'||CHR(10)||'
    SQL>

  • Pls Help with a query

    Problem Scope:
    Two tables with different set of columns,
    Only common column being "emplid"--employee id.
    table1 has 2 columns "emplid" and "effdt"- effective date.
    table2 has 3 columns "emplid", "start date" and "end date".
    So structure of the tables will be:
    1. table1: emplid, effdt
    2. table2: emplid, start_date, end_date
    Need to find out all the records from table2, where
    "table2.start_date" falls between 2 "table1.effdt" rows for the same employee.
    For example for an emplid "G1234",
    table 1 data: emplid, effdt
    G1234, 01/01/1990
    G1234, 01/01/1994
    table 2 data: emplid, start date
    G1234, 01/01/1993
    G1234, 01/01/2001
    For the above scenario, query should return the row: G1234, 01/01/1993 from table 2 as it(start date) falls between two effdt from table 1.
    Pls advice,
    Thanks

    Seems to be my day for LAG and LEAD.
    Does this work for you?
    SQL> SELECT * FROM t1;
         EMPID EFF_DT
          1234 01-jan-1990
          1234 01-jan-1994
    SQL> SELECT * FROM t2;
         EMPID START_DT    END_DT
          1234 01-jan-1993 31-dec-2000
          1234 01-jan-2001
    SQL> SELECT t2.empid, t2.start_dt, t2.end_dt
      2  FROM t2,
      3       (SELECT empid, eff_dt,
      4               LEAD(eff_dt) OVER (PARTITION BY empid
      5                                  ORDER BY eff_dt) next_eff
      6        FROM t1) t1
      7  WHERE t2.empid = t1.empid and
      8        t2.start_dt BETWEEN t1.eff_dt and t1.next_eff;
         EMPID START_DT    END_DT
          1234 01-jan-1993 31-dec-2000John

  • Pls. help tune this query

    This is the SQL i would like to tune for performace...
    The table structure is given below.
    The table has about 5 million rows.
    On the first day, load_flag has all the rows as 'I'.
    Then from the second day onwards only around 10% of records will be between Load_Start_Time and Load_End_Time. Among these around 40% will have Record_key like 'TP%'. And among those most of the records (95%)will have load_flag as 'U' and a very few (5%) as 'I'. At present there are unique and primary key indexes on record_key. Please advice me whether it's better to go for an index on any of these columns and what type would be better. I thought it would help to have a bit map index on load_flag and a function base index on SUBSTR (RECORD_KEY).
    Also pls. let me know if the order of predicates is right.
    Thanks in advance.
    M_STG_TPDB_TPD_TL_W_PH_LOI_CNTBLTY_STATUS_CE     SQ_STG_TPD_STG_TL_CS_EXTRACTED_RECS_MOD     "SELECT TPD_STG_TL_CS_EXTRACTED_RECS.RECORD_KEY, TPD_STG_TL_CS_EXTRACTED_RECS.DATA_SOURCE, TPD_STG_TL_CS_EXTRACTED_RECS.CONTACTABLE_INDICATOR, TPD_STG_TL_CS_EXTRACTED_RECS.LEGAL_OWNERSHIP_ISSUE_IND, TPD_STG_TL_CS_EXTRACTED_RECS.ADMIN_CONTROL_INDICATOR, TPD_STG_TL_CS_EXTRACTED_RECS.BANKRUPTCY_INDICATOR, TPD_STG_TL_CS_EXTRACTED_RECS.ASSIGNED_INDICATOR, TPD_STG_TL_CS_EXTRACTED_RECS.IN_TRUST_INDICATOR, TPD_STG_TL_CS_EXTRACTED_RECS.DIVORCE_CASE_INDICATOR, TPD_STG_TL_CS_EXTRACTED_RECS.POA_COP_INDICATOR, TPD_STG_TL_CS_EXTRACTED_RECS.SOURCE_EXTRACT_DATE_TIME
    FROM
    TPD_STG_TL_CS_EXTRACTED_RECS
    WHERE
    LOAD_FLAG IN ('I','U')
    AND SUBSTR (RECORD_KEY, 1,2)='TP'
    AND STG_UPDATE_DATE_TIME>'$$Load_Start_Time'
    AND STG_UPDATE_DATE_TIME<='$$Load_End_Time'"
    Table structure
    CREATE TABLE TPD_STG_TL_CS_EXTRACTED_RECS
    RECORD_KEY VARCHAR2(35 BYTE),
    SCHEME_NAME VARCHAR2(50 BYTE),
    ORGANISATION_NAME VARCHAR2(50 BYTE),
    SUPERIOR_TITLE_1 VARCHAR2(50 BYTE),
    TITLE_1 VARCHAR2(50 BYTE),
    FIRST_NAME_1 VARCHAR2(50 BYTE),
    MIDDLE_NAME_1 VARCHAR2(50 BYTE),
    SURNAME_1 VARCHAR2(50 BYTE),
    ADDRESS_LINE_1_1 VARCHAR2(50 BYTE),
    ADDRESS_LINE_2_1 VARCHAR2(50 BYTE),
    ADDRESS_LINE_3_1 VARCHAR2(50 BYTE),
    ADDRESS_LINE_4_1 VARCHAR2(50 BYTE),
    ADDRESS_LINE_5_1 VARCHAR2(50 BYTE),
    ADDRESS_LINE_6_1 VARCHAR2(50 BYTE),
    POST_CODE_1 VARCHAR2(12 BYTE),
    COUNTRY_1 VARCHAR2(50 BYTE),
    OVERSEAS_INDICATOR_1 CHAR(1 BYTE),
    DOB_1 NUMBER(8),
    GENDER_1 CHAR(1 BYTE),
    NINO_1 VARCHAR2(9 BYTE),
    DEATH_INDICATOR_1 CHAR(1 BYTE),
    PRODUCT_HOLDING_ROLE_TYPE_1 VARCHAR2(21 BYTE),
    GONE_AWAY_INDICATOR_1 CHAR(1 BYTE),
    THAMES_LEGAL_OWNERSHIP_IND_1 CHAR(1 BYTE),
    SOURCE_SYSTEM_PARTY_INDV_ID_1 VARCHAR2(15 BYTE),
    SUPERIOR_TITLE_2 VARCHAR2(50 BYTE),
    TITLE_2 VARCHAR2(50 BYTE),
    FIRST_NAME_2 VARCHAR2(50 BYTE),
    MIDDLE_NAME_2 VARCHAR2(50 BYTE),
    SURNAME_2 VARCHAR2(50 BYTE),
    ADDRESS_LINE_1_2 VARCHAR2(50 BYTE),
    ADDRESS_LINE_2_2 VARCHAR2(50 BYTE),
    ADDRESS_LINE_3_2 VARCHAR2(50 BYTE),
    ADDRESS_LINE_4_2 VARCHAR2(50 BYTE),
    ADDRESS_LINE_5_2 VARCHAR2(50 BYTE),
    ADDRESS_LINE_6_2 VARCHAR2(50 BYTE),
    POST_CODE_2 VARCHAR2(12 BYTE),
    COUNTRY_2 VARCHAR2(50 BYTE),
    OVERSEAS_INDICATOR_2 CHAR(1 BYTE),
    DOB_2 NUMBER(8),
    GENDER_2 CHAR(1 BYTE),
    NINO_2 VARCHAR2(9 BYTE),
    DEATH_INDICATOR_2 CHAR(1 BYTE),
    PRODUCT_HOLDING_ROLE_TYPE_2 VARCHAR2(21 BYTE),
    GONE_AWAY_INDICATOR_2 CHAR(1 BYTE),
    THAMES_LEGAL_OWNERSHIP_IND_2 CHAR(1 BYTE),
    SOURCE_SYSTEM_PARTY_INDV_ID_2 VARCHAR2(15 BYTE),
    JOINT_OWNER_INDICATOR CHAR(1 BYTE),
    JOINT_LIFE_TYPE NUMBER(1),
    SAME_ADDRESS_INDICATOR CHAR(1 BYTE),
    TITLE_LA1 VARCHAR2(50 BYTE),
    FIRST_NAME_LA1 VARCHAR2(50 BYTE),
    SURNAME_LA1 VARCHAR2(50 BYTE),
    DOB_LA1 NUMBER(8),
    TITLE_LA2 VARCHAR2(50 BYTE),
    FIRST_NAME_LA2 VARCHAR2(50 BYTE),
    SURNAME_LA2 VARCHAR2(50 BYTE),
    DOB_LA2 NUMBER(8),
    PRODUCT_HOLDING_REF_NUMBER VARCHAR2(28 BYTE),
    PARENT_PRODUCT_HOLDING_REF_NUM VARCHAR2(9 BYTE),
    OCDB_REFERENCE_NUMBER VARCHAR2(17 BYTE),
    BUSINESS_GROUP CHAR(3 BYTE),
    SCHEME_NUMBER VARCHAR2(8 BYTE),
    TRUSTEE_SEQUENCE_NUMBER NUMBER(10),
    MEMBER_NUMBER VARCHAR2(10 BYTE),
    PRSN_ID NUMBER(10),
    OLD_SCHEME_NUMBER VARCHAR2(8 BYTE),
    PUBLIC_SECTOR_INDICATOR CHAR(1 BYTE),
    ELIGIBLE_INDICATOR CHAR(1 BYTE),
    SCHEME_STATUS NUMBER(1),
    SCHEME_TYPE CHAR(2 BYTE),
    Q_DATE_WITH_PROFIT_STATUS NUMBER(1),
    A_DATE_WITH_PROFIT_STATUS NUMBER(1),
    LATEST_WITH_PROFIT_STATUS NUMBER(1),
    NPSW_INDICATOR CHAR(1 BYTE),
    PRODUCT_HOLDING_STATUS CHAR(1 BYTE),
    MATURITY_DATE_OF_CONTRACT NUMBER(8),
    DUE_END_DATE_OF_CONTRACT NUMBER(8),
    OUT_OF_FORCE_DATE NUMBER(8),
    OUT_OF_FORCE_REASON_CODE NUMBER(2),
    DATA_SOURCE VARCHAR2(3 BYTE),
    PRODUCT_TYPE VARCHAR2(30 BYTE),
    PRODUCT_DESCRIPTION VARCHAR2(50 BYTE),
    SERVICING_AGENT_NUMBER VARCHAR2(10 BYTE),
    CONTACTABLE_INDICATOR CHAR(1 BYTE),
    LEGAL_OWNERSHIP_ISSUE_IND CHAR(1 BYTE),
    ADMIN_CONTROL_INDICATOR CHAR(1 BYTE),
    BANKRUPTCY_INDICATOR CHAR(1 BYTE),
    ASSIGNED_INDICATOR CHAR(1 BYTE),
    IN_TRUST_INDICATOR CHAR(1 BYTE),
    DIVORCE_CASE_INDICATOR CHAR(1 BYTE),
    POA_COP_INDICATOR CHAR(1 BYTE),
    DONOR_POLICY_INDICATOR CHAR(1 BYTE),
    TAX_JURISDICTION NUMBER(2),
    INELIGIBLE_DATE NUMBER(8),
    INELIGIBILITY_REASON NUMBER(2),
    A_DATE_CASH_OR_BONUS_TYPE CHAR(1 BYTE),
    VALUATION_APPLICABLE_DATE NUMBER(8),
    A_DATE_PIP_AMOUNT NUMBER(12),
    A_DATE_NPSW_AMOUNT NUMBER(10),
    A_DATE_MINIMUM_APPLIED_AMOUNT NUMBER(10),
    A_DATE_MINIMUM_CALC_AMOUNT NUMBER(10),
    A_DATE_POLICY_VALUE NUMBER(16),
    A_DATE_DATE_PIP_CALCULATED NUMBER(8),
    A_DATE_ALGORITHM_NUMBER NUMBER(2),
    M_DATE_VOTING_VALUE NUMBER(12),
    M_DATE_POLICY_VALUE NUMBER(16),
    E_DATE_CASH_OR_BONUS_TYPE CHAR(1 BYTE),
    E_DATE_PIP_AMOUNT NUMBER(12),
    E_DATE_NPSW_AMOUNT NUMBER(10),
    E_DATE_MINIMUM_APPLIED_AMOUNT NUMBER(10),
    E_DATE_MINIMUM_CALC_AMOUNT NUMBER(10),
    E_DATE_POLICY_VALUE NUMBER(16),
    E_DATE_DATE_PIP_CALCULATED NUMBER(8),
    E_DATE_ALGORITHM_NUMBER NUMBER(2),
    P_DATE_CASH_OR_BONUS_TYPE CHAR(1 BYTE),
    P_DATE_PIP_AMOUNT NUMBER(12),
    P_DATE_NPSW_AMOUNT NUMBER(10),
    P_DATE_MINIMUM_APPLIED_AMOUNT NUMBER(10),
    P_DATE_MINIMUM_CALC_AMOUNT NUMBER(10),
    P_DATE_POLICY_VALUE NUMBER(16),
    P_DATE_DATE_PIP_CALCULATED NUMBER(8),
    P_DATE_ALGORITHM_NUMBER NUMBER(2),
    SOURCE_EXTRACT_DATE_TIME DATE,
    SCHEME_SEQUENCE_NUMBER NUMBER(3),
    LOAD_FLAG CHAR(1 BYTE),
    STG_CREATE_DATE_TIME DATE,
    STG_UPDATE_DATE_TIME DATE
    TABLESPACE TPDBS01A_DATA
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 128K
    NEXT 128K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    LOGGING
    NOCOMPRESS
    NOCACHE
    NOPARALLEL
    MONITORING;
    CREATE UNIQUE INDEX PK_STG_TL_CS_EXTRACTED_RECS ON TPD_STG_TL_CS_EXTRACTED_RECS
    (RECORD_KEY)
    LOGGING
    TABLESPACE TPDBS01A_DATA
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 128K
    NEXT 128K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    NOPARALLEL;
    ALTER TABLE TPD_STG_TL_CS_EXTRACTED_RECS ADD (
    CONSTRAINT PK_STG_TL_CS_EXTRACTED_RECS
    PRIMARY KEY
    (RECORD_KEY)
    USING INDEX
    TABLESPACE TPDBS01A_DATA
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 128K
    NEXT 128K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    ));

    I would like to discuss a bit more how a composite index is used. This is not anymore the question of the OP, but I think it will deepen my understanding and maybe that of others as well.
    So we have this situation to start with.
    * A select on two different columns.
    * An index on each column would lead to an INDEX RANGE SCAN because of the where condition.
    * Instead of 2 indexes where only one would be used (not considering bitmap conversions), we add a composite index on both columns.
    * The CBO will choose and access the index.
    Question is: How is this access is done in detail?
    So 400 rows come out of the index range scan.
    This would not be possible if it only scanned one of the two predicates. I agree. The output of the index seem to be only those (400) rows that fit with the where clause on both columns.
    This is supported by the fact that an Index only access is possible when we select only information that is in the index (Oracle 9i output).
    SQL> explain plan for
      2  select record_key
      3  from mytable
      4  where stg_update_date_time >= to_date('2007-11-11','yyyy-mm-dd')
      5  and stg_update_date_time < to_date('2007-11-12','yyyy-mm-dd')
      6  and record_key like 'TP%'
      7  /
    Explained.
    SQL>  select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id  | Operation            |  Name       | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT     |             |   160 |  2400 |     2 |
    |   1 |  INDEX RANGE SCAN    | I1          |   160 |  2400 |     2 |
    Note: cpu costing is off, PLAN_TABLE' is old version
    9 rows selected.
    SQL> Unfortunately I don't see the filter operation, probably because the plan table is old in my system.
    The index is build on columns "stg_update_date_time" and "record_key". So it must access these columns in that order.
    I think, that maybe the range scan is done on the date column and then a further access/filter operation is done to rule out any index entries (leaf nodes) that do not fit with the LIKE 'TP%' expression.
    Since I expect that is is faster to access the data in the index than in the table this should improve performance quite a bit. It is not the same access plan/speed however as with a clause like this:
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id  | Operation                   |  Name       | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT            |             |     1 |   520 |     3 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| MYTABLE     |     1 |   520 |     3 |
    |   2 |   INDEX RANGE SCAN          | I1          |     1 |       |     2 |
    Note: cpu costing is off, PLAN_TABLE' is old version
    10 rows selected.
    SQL> The difference can be seen in the cost estimation.
    I hope somebody does understand what I would like to point at.
    Result of this considerations:
    1) Composite index can be used
    2) The index is used as a range scan on one column and as a filter operation after this access on the second column. This is like an extra select statement inside the index structure.
    3) The resulting table access is as small as possible.
    4) A faster access plan can be achieved when the first column is accessed with direct (unique) scan on the first and a range scan on the second column.
    br Sven
    Message was edited by:
    Sven Weller

  • Hi!!Pls help !!Query Urgent!!

    Hi  all
    We have a ABC classification with respect to the char.ABC class  based on the Total Vlaue(New Query),
    We have already created with Analysis Processs designer based on the Shopping cart value(orginal Query) & they have restricted in the (orginal Query) too.
    TOTAL VALUE CODING:
    IF <result_fields>-/bic/ztotal_it > 30000000.
            <result_fields>-abc_class = 'A'.
          ELSEIF <result_fields>-/bic/ztotal_it BETWEEN 10000001 AND
          30000000.
            <result_fields>-abc_class = 'B'.
          .    ENDLOOP.
    My question to clarify is that do I have to change the restricted char with Shopping cart values(orginal Query) to my present TOTAL VALUE(New Query),.
    But if suppose I am changing it in TOTAL VALUE(New Query), ,it will reflect the Shopping cart values (Original query) also as it has been copied frm the original query.
    pls anyone revert to me ASAP.
    thnx IN ADVANCE

    Hi
    We are calculating the total Value based on char ABC classification like the following:
    IF ztotal_it  > 30000000.
    _class = 'A'.
    ELSEIF ztotal_it BETWEEN 10000001 AND 30000000.
    abc_class = 'B'.
    I have created this ,not sure whether this is correct,I have found in the query,some calculated key figures r used,So i want to know do i have to change the calculated key figure also, as I am not getting any data while executing in RSRT.
    Leave my previous question...
    pls clarify me this anyone & tell whether the routine is right & it has to be end routine or start routine???

  • Pls help with this query

    Hello
    If I run the following query I correctly get a sum of the invoices for a particular BP for Jan 09
    SELECT T1.[SlpName], T0.[CardCode], SUM(CASE WHEN  T2.[DocDate] BETWEEN '20090101' AND '20090131' THEN (T2.[DocTotal] -  T2.[VatSum]) ELSE 0 END) AS 'JAN 09' FROM OCRD T0  INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode INNER JOIN OINV T2 ON T0.CardCode = T2.CardCode WHERE T0.[CardCode] = 'KEY065' GROUP BY T0.[CardCode], T1.[SlpName]
    However I need the value of credit notes to be reflected in the figure so I amended the query to be:
    SELECT T1.[SlpName], T0.[CardCode], SUM(CASE WHEN  T2.[DocDate] BETWEEN '20090101' AND '20090131' THEN (T2.[DocTotal] -  T2.[VatSum])ELSE 0 END) - SUM(CASE WHEN  T3.[DocDate] BETWEEN '20090101' AND '20090131' THEN (T3.[DocTotal] -  T3.[VatSum]) ELSE 0 END) AS 'JAN 09' FROM OCRD T0  INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode INNER JOIN OINV T2 ON T0.CardCode = T2.CardCode INNER JOIN ORIN T3 ON T0.CardCode = T3.CardCode WHERE T0.[CardCode] = 'KEY065' GROUP BY T0.[CardCode], T1.[SlpName]
    When I run this query the output is incorrect ................ Is the fault to do with my JOINS?
    Thanks

    Hi Just to clarify
    This query, which just totals any invoices for a BP for January, correctly returns a value of £9660.44 :
    SELECT T1.[SlpName], T0.[CardCode], SUM(CASE WHEN  T2.[DocDate] BETWEEN '20090101' AND '20090131' THEN (T2.[DocTotal] -  T2.[VatSum]) ELSE 0 END) AS 'JAN 09' FROM OCRD T0  INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode INNER JOIN OINV T2 ON T0.CardCode = T2.CardCode  WHERE T0.[CardCode] = 'KEY065' GROUP BY T0.[CardCode], T1.[SlpName]
    This next query, which just totals any credit notes for a BP in January, correctly returns a value of £567.73 :
    SELECT T1.[SlpName], T0.[CardCode], SUM(CASE WHEN  T3.[DocDate] BETWEEN '20090101' AND '20090131' THEN (T3.[DocTotal] -  T3.[VatSum]) ELSE 0 END) AS 'JAN 09' FROM OCRD T0  INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode INNER JOIN ORIN T3 ON T0.CardCode = T3.CardCode WHERE T0.[CardCode] = 'KEY065' GROUP BY T0.[CardCode], T1.[SlpName]
    I want a query which return a value of 9660.44 minus 567.73 (ie £9092.71)
    My original effort at this returned -£82,608.65 !!!!!!!!!
    and Gordon's amended version returned -£40,281.74 !!!!!
    Thanks for your patience
    Steve

  • SQL query...pls help ASAP

    Actor (Aname: varchar(40), Ano: varchar(6)) Ano is pk
    Movie (Mname: varchar(40),mno: varchar(8)) Mno is pk
    PlayIn (Ano, Mno, Pay: Integer) Ano and Mno are fk referencing Acotr and Movie respectively.
    Actor(Aname, Ano)
    A Bingo, A1
    B Castro, A2
    C Katie, A3
    S Hommy, A4
    J Tammy, A5
    K loren, A6
    Movie(Mname, Mno)
    Gladiator, M1
    Cast, M2
    Dog, M3
    Jilters, M4
    PlayIn(Ano,Mno,Pay)
    A1 M1 800
    A1 M2 1500
    A2 M2 78
    A2 M3 1750
    A2 M4 2301
    A3 M2 904
    A3 M3 629
    A4 M2 565
    A4 M3 5695
    A4 M4 1255
    A5 M1 989
    A5 M4 238
    A6 M2 137
    A6 M3 236
    A6 M4 545
    QUESTION: write SQL query to find the names of actors who earned less than 'B Castro' in each movie that 'B Castro' played in.

    thanks so so much.....
    another question:
    for each movie, list the movie number, the average
    pay and the total number of actors in the movie.....Rather than just asking homework questions and expecting everyone else to do your work for you, why don't you at least have a go at it yourself and post the query that you've tried, then we'll tell you where you are going wrong. You won't learn anything if we just write it for you.
    Also, your use of "pls help ASAP" in the subject title is not polite.
    This forum is manned by volunteers who have their own jobs and offer their help free of charge.
    Everyone who posts an issue on here would love to have it answered as soon as possible, but nobody has the right to assume that their issue is any more important, urgent or requires a quicker answer than anybody elses.
    If you need urgent help then you should pay someone to do the work for you.

  • Query on Time Scheduling ............................Urgent pls help

    Dear Friends
      Here is my query on Background processing,
      I want to run a program in background which ll save the details in AL11.
      I want to schedule this object between 12 AM night to 2 AM night as per the indian time standard.
      The data should be save the data in al11 as the following format=>
      1-It ll show the PO details that has been created between 12-1 and 1-2,it should not show 12-1 data in 1-2 means between 12 to 2 i ll store the data in AL11 that has been created between these one hour time if it would more than one hour than last one hour data it wont show in al11.
      Now the Pos that has been created between 2 am to next day night should be display when the user ll run the report at next day 12 o'clock.
    Can you give me the following idea,
    1-Which table stores the background scheduling time,if NAST than what is the field name.
    If anyone solve this kind of prob,pls help me on this.
    Thanks a lot
    mrutyun^

    Hi,
    Try table<b> TBTCS</b> which stores Background Processing: Time Schedule.
    Regards,
    Amit

  • Consecutive Absent Days  Query.. Pls Help Gurus

    I have a table which stores attendance information
    For eg:
    Emp_No Date
    100 01-APR-2010
    102 05-APR-2010
    100 02-APR-2010
    I need a query with parameter From Date and To date..
    My Query Output should be like this .. considering that employee 100 is absent for 8 consecutive days and employee number 102 is absent for 2 consecutive days..
    It should return number of consecutive days he is absent.
    Empno Consecutive Days
    100 8 Days
    102 2 Days
    Pls Help Gurus.
    Edited by: suzvino on Jun 21, 2010 12:14 AM

    TUBBY_TUBBZ?with data as
      2  (
      3     select 100 as emp_no, to_date('01-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      4     select 102 as emp_no, to_date('05-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      5     select 100 as emp_no, to_date('02-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      6     select 100 as emp_no, to_date('01-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      7     select 100 as emp_no, to_date('03-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      8     select 100 as emp_no, to_date('04-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      9     select 100 as emp_no, to_date('05-APR-2010','dd-mon-yyyy') as absent_date from dual union all
    10     select 100 as emp_no, to_date('06-APR-2010','dd-mon-yyyy') as absent_date from dual union all
    11     select 100 as emp_no, to_date('07-APR-2010','dd-mon-yyyy') as absent_date from dual union all
    12     select 100 as emp_no, to_date('08-APR-2010','dd-mon-yyyy') as absent_date from dual union all
    13     select 100 as emp_no, to_date('09-APR-2010','dd-mon-yyyy') as absent_date from dual
    14  )
    15  select
    16     emp_no, max(level)
    17  from data
    18  connect by prior emp_no = emp_no and prior absent_date = absent_date - 1
    19  group by emp_no
    20  having max(level) >= 8;
                EMP_NO         MAX(LEVEL)
                   100                  9
    1 row selected.
    Elapsed: 00:00:00.01
    TUBBY_TUBBZ?Think i misread the post, so the query should be
    TUBBY_TUBBZ?with data as
      2  (
      3     select 100 as emp_no, to_date('01-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      4     select 102 as emp_no, to_date('05-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      5     select 100 as emp_no, to_date('02-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      6     select 100 as emp_no, to_date('01-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      7     select 100 as emp_no, to_date('03-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      8     select 100 as emp_no, to_date('04-APR-2010','dd-mon-yyyy') as absent_date from dual union all
      9     select 100 as emp_no, to_date('05-APR-2010','dd-mon-yyyy') as absent_date from dual union all
    10     select 100 as emp_no, to_date('06-APR-2010','dd-mon-yyyy') as absent_date from dual union all
    11     select 100 as emp_no, to_date('07-APR-2010','dd-mon-yyyy') as absent_date from dual union all
    12     select 100 as emp_no, to_date('08-APR-2010','dd-mon-yyyy') as absent_date from dual union all
    13     select 100 as emp_no, to_date('09-APR-2010','dd-mon-yyyy') as absent_date from dual
    14  )
    15  select
    16     emp_no, max(level)
    17  from data
    18  connect by prior emp_no = emp_no and prior absent_date = absent_date - 1
    19  group by emp_no;
                EMP_NO         MAX(LEVEL)
                   100                  9
                   102                  1
    2 rows selected.
    Elapsed: 00:00:00.01Edited by: Tubby on May 30, 2010 11:00 PM
    Added second query since i misread the post originally.

  • Complex query pls help

    I have a row output like this
    select * from test;
    s.no C1 C2 C3
    1 a1 b1 x1
    2 a1 b1 x2
    3 a1 b1 x3
    i want the output as with the new added column as like this
    s.no C1 C2 C3 C4
    1 a1 b1 x1 a1
    2 a1 b1 x2 b1
    3 a1 b1 x3 x3
    pls help me in this query its urgent for the solution

    Hello,
    So, what is the complexity in this query? Would you like to mention from where you will get that C4 column?
    -Ammad

  • Query-Automatic assignment of Record type to Book of Business-Pls help me

    I have a query about Automatic assignment of record in Book of Business.
    Using 5 record types & 50 regions as a part of Book of Business. You can say 50 sub-books.
    I want to assign these 5 record type to particular Book when to create & modify.
    Eg. When I create new account it should be automatically assigned to Book 1 & later I modify this account for reassignment to new user then it should be automatically added to the new user’s book.
    I need to create workflow for this as Assign to book criteria for both when new record saved & when modified record saved.
    I have tried this & its working; however problem is with the creation of two many workflows.
    50 region (Books) x 5 record types * 2 - Create/modify flow = 500 workflows for one country!
    If I am right then I can assign 1 record type with action as create or modify in 1 book only.
    How to reduce these no. of workflows?
    Pls help me out in this regard.
    Regards
    Mangesh

    Mangesh,
    I am sorry to tell you that there is no quick answer to this but i will say that maybe you need to rethink your book structure and their requirements here.
    I have 4 types and 7 regions so you need to create books to allocate all these on create and also modify. Customers have raised concerns with this to Oracle and they are looking into it but they are along way from completing this. Sorry to spoil your day but i would strongly ask you to consider your books structure before you complete this.
    Otherwise if you are using webservices you could assisgn the book when the record is piped into the CRM and then you only need to complete the modify workflows.

  • QUERY CLARIFICATION RQD :  gurus, experts pls help

    Hai,
    I am facing problem in performance of the query. sample scenario i have created here pls help me to solve
    **VEH_MAIN* TABLE (MASTER TABLE)*
    CREATE TABLE VEH_MAIN
       (     VIP_MOT_IND VARCHAR2(10 BYTE),
         VIP_IND NUMBER(10,0)
    Insert into VEH_MAIN (VIP_MOT_IND,VIP_IND) values ('MOT01',1);
    Insert into VEH_MAIN (VIP_MOT_IND,VIP_IND) values ('MOT02',5);
    Insert into VEH_MAIN (VIP_MOT_IND,VIP_IND) values ('M0T03',1);
    Insert into VEH_MAIN (VIP_MOT_IND,VIP_IND) values ('MOT01',2);
    Insert into VEH_MAIN (VIP_MOT_IND,VIP_IND) values ('MOT02',6);
    Insert into VEH_MAIN (VIP_MOT_IND,VIP_IND) values ('MOT01',3);
    Insert into VEH_MAIN (VIP_MOT_IND,VIP_IND) values ('MOT01',4);
    **VEH_ENGINE_SUB* (table for engine subclass)*
      CREATE TABLE VEH_ENG_SUB
       (     ENG_SUBCLASS VARCHAR2(50 BYTE),
         ENG_MOT_IND VARCHAR2(10 BYTE)
    Insert into VEH_ENG_SUB (ENG_SUBCLASS,ENG_MOT_IND) values ('ENGSUB001','MOT01');
    Insert into VEH_ENG_SUB (ENG_SUBCLASS,ENG_MOT_IND) values ('ENGSUB001','MOT02');
    *VEH_ENG_IND( Detail table for engine subclass)*
      CREATE TABLE VEH_ENG_IND
       (     "ENG_SUBCLASS" VARCHAR2(50 BYTE),
         "ENG_IND" VARCHAR2(10 BYTE)
    Insert into VEH_ENG_IND (ENG_SUBCLASS,ENG_IND) values ('ENGSUB001','1');
    Insert into VEH_ENG_IND (ENG_SUBCLASS,ENG_IND) values ('ENGSUB001','2');
    *VEH_AXIS( Master table for Engine Axis)*
    CREATE TABLE VEH_AXIS
       (     ENG_AXIS VARCHAR2(50 BYTE),
         AXIS_MOT_IND VARCHAR2(10 BYTE)
    Insert into VEH_AXIS (ENG_AXIS,AXIS_MOT_IND) values ('ENGAXIS001','MOT01');
    Insert into VEH_AXIS (ENG_AXIS,AXIS_MOT_IND) values ('ENGAXIS002','MOT02');
    *VEH_AXIS_IND( Details table for engine axis)*
    CREATE TABLE VEH_AXIS_IND
       (     ENG_AXIS VARCHAR2(50 BYTE),
         ENG_IND VARCHAR2(10 BYTE)
    Insert into VEH_AXIS_IND (ENG_AXIS,ENG_IND) values ('ENGAXIS001','1');
    Insert into VEH_AXIS_IND (ENG_AXIS,ENG_IND) values ('ENGAXIS001','2');
    Insert into VEH_AXIS_IND (ENG_AXIS,ENG_IND) values ('ENGAXIS001','3');
    Insert into VEH_AXIS_IND (ENG_AXIS,ENG_IND) values ('ENGAXIS001','4');
    Insert into VEH_AXIS_IND (ENG_AXIS,ENG_IND) values ('ENGAXIS002','5');
    Insert into VEH_AXIS_IND (ENG_AXIS,ENG_IND) values ('ENGAXIS002','6');
    Condition 1
    if i select only ENGINE_SUBCLASS='ENGSUB001' then
    SELECT  vip_mot_ind,vip_ind
    FROM veh_main V,
    veh_eng_sub vsub,
    veh_eng_ind  vind
    WHERE (v.vip_mot_ind= vsub.eng_mot_ind
    and   v.vip_ind=vind.eng_ind
    and    vsub.eng_subclass= vind.eng_subclass
    AND vsub.eng_subclass='ENGSUB001' )output is
    MOT01     1
    MOT01     2
    Condition 2:if i select only the Engine Axis='ENGAXIS002' then the
    SELECT  vip_mot_ind,vip_ind
    FROM veh_main V,
    veh_axis  vaxis,
    veh_axis_ind vaind
    WHERE  v.vip_mot_ind= vaxis.axis_mot_ind
    and   v.vip_ind= vaind.eng_ind
    and   vaind.eng_axis= vaxis.eng_axis
    and   vaxis.eng_axis='ENGAXIS002';MOT02     5
    MOT02     6
    Condition 3:
    BOTH ENGINE AXIS AND ENGINE SUBCLASS
    SELECT  vip_mot_ind,vip_ind
    FROM veh_main V,
    veh_eng_sub vsub,
    veh_eng_ind  vind,
    veh_axis  vaxis,
    veh_axis_ind vaind
    WHERE (v.vip_mot_ind= vsub.eng_mot_ind
    and   v.vip_ind=vind.eng_ind
    and    vsub.eng_subclass= vind.eng_subclass
    AND vsub.eng_subclass='ENGSUB001' )
    AND  ( v.vip_mot_ind= vaxis.axis_mot_ind
    and   v.vip_ind= vaind.eng_ind
    and   vaind.eng_axis= vaxis.eng_axis
    and   vaxis.eng_axis='ENGAXIS002');Null values returned. this is correct.
    But the query PERFORMANCE fails in OR CONDITON as below
    Condition 4;
    SELECT  vip_mot_ind,vip_ind
    FROM veh_main V,
    veh_eng_sub vsub,
    veh_eng_ind  vind,
    veh_axis  vaxis,
    veh_axis_ind vaind
    WHERE (v.vip_mot_ind= vsub.eng_mot_ind
    and   v.vip_ind=vind.eng_ind
    and    vsub.eng_subclass= vind.eng_subclass
    AND vsub.eng_subclass='ENGSUB001' )
    OR  ( v.vip_mot_ind= vaxis.axis_mot_ind
    and   v.vip_ind= vaind.eng_ind
    and   vaind.eng_axis= vaxis.eng_axis
    and   vaxis.eng_axis='ENGAXIS002');output
    MOT02     5
    MOT02     5
    MOT02     5
    MOT02     5
    MOT02     6
    MOT02     6
    MOT02     6
    MOT02     6
    MOT01     1
    MOT01     1
    MOT01     1
    MOT01     1
    MOT01     1
    MOT01     1
    MOT01     1
    MOT01     1
    MOT01     1
    MOT01     1
    MOT01     1
    MOT01     1
    MOT01     2
    MOT01     2
    MOT01     2
    MOT01     2
    MOT01     2
    MOT01     2
    MOT01     2
    MOT01     2
    MOT01     2
    MOT01     2
    MOT01     2
    MOT01     2
    This is sample example. when i implement in huge table with partition this scennario takes much time even 2 hours to run.
    i want the output must be as below if i use OR condition like condition 4
    MOT01     1
    MOT01     2
    MOT02     5
    MOT02     6
    Gurus and experts pls help me to solve this problem. Dont give any suggestion like
    SELECT  vip_mot_ind,vip_ind
    FROM veh_main V,
    veh_axis  vaxis,
    veh_axis_ind vaind
    WHERE  v.vip_mot_ind= vaxis.axis_mot_ind
    and   v.vip_ind= vaind.eng_ind
    and   vaind.eng_axis= vaxis.eng_axis
    and   vaxis.eng_axis='ENGAXIS002'
    union
    SELECT  vip_mot_ind,vip_ind
    FROM veh_main V,
    veh_eng_sub vsub,
    veh_eng_ind  vind
    WHERE (v.vip_mot_ind= vsub.eng_mot_ind
    and   v.vip_ind=vind.eng_ind
    and    vsub.eng_subclass= vind.eng_subclass
    AND vsub.eng_subclass='ENGSUB001' )
    }this will give correct result...
    MOT01     1
    MOT01     2
    MOT02     5
    MOT02     6
    but the problem is we cannot implement this in query. because query get framed at runtime there will be so many implement has to be done. other than UNION pls give me more suggesion
    waiting..
    S
    Edited by: A Beginner on Sep 11, 2010 12:51 AM

    create a view v1 with all the joins
    select * from v1 where eng_subclass='ENGSUB001'
    union
    select * from v1 where eng_axis='ENGAXIS002'
    If you really do not like the direct access with union, try this
    select * from v1
    where vsub_PK in (select vsub_PK from v1 where eng_subclass='ENGSUB001' )
    OR vsub_PK in (select vsub_PK from v1 where eng_axis='ENGAXIS002')
    --vsub_PK is the primary key of table vsub                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Cursor Query Pls help me

    Hi all,
    I m creating a table dynamically and after that i m inserting records in tht table dynamically..
    After tht i want to fetch all the records from tht table into a cursor which is a SYS_REFCURSOR. as i have to return the data to frntend ..
    But when i m opening tht cursor like
    OPEN cur_GetCertDetails
                   FOR
                   SELECT TRIM(certrefno) As CertNo,
                                  TRIM(damagedno) As Damagedno,
                                  TRIM(personname) As Name,
                                  TRIM(icnumber) As Icnumber,
                                  TRIM(coursename) As CourseName,
                                  TRIM(organiser) As Organiser,
                                  TRIM(location) As Location,
                             TRIM(TO_CHAR(startdate,'DD-MON-YYYY') ||' ~ '||
                                  TO_CHAR(enddate,'DD-MON-YYYY')) As StartEndDate
                             FROM ACprintInductionCert;
    Its giving error as
    64/5 PL/SQL: SQL Statement ignored
    73/10 PL/SQL: ORA-00942: table or view does not exist
    Dynamically created table name is ACprintInductionCert
    Pls help me out ..
    I have tried to use EXECUTE IMMEDIATE after FOR but its givin err

    since your table is created dynamically, you can not
    have the name hardcoded in the cursor....which is precisely the point (or one of them) I made in your Procedure Problem Urgent on this topic.
    Once you start down the road of dynamic code execution it is very difficult to stop. Dynamic code has its uses but it should be very much the last resort. Dynamic code means you are literally running untested code in a production environment, and is consequently more likely to fail. Its failures are also more difficult to recover from. It also makes dependency tracking extremely difficult.
    Cheers, APC

  • Select query. pls help

    Hi all
    i am new to abap
    I have the following requirement.
    kindly help me how to write the select queries to achieve it.
    its urgent
    pls help me
    thanks in advance
    In June of year 1, new budget prices must be determined for the following year (year 2). The budget prices for year 2 are calculated out of the average contract prices in the first 5 months of year 1 (January – May). The average contract price will then (outside the system) be corrected with an index. To calculate new prices for Campina Netherlands, a report is needed to show all materials with current budget price, volumes and contract prices during the first five months of year 1
    The purchasing assistant creates an excel file per Material type, based on the Budget pricelist out of SAP.
    Purchasers check the file on:
    &#61485;     being correct,
    &#61485;     materials marked for deletion in SAP
    &#61485;     changes to be made in data
    The new prices, calculated based ion the output of the SAP Budget pricelist, are sent to controlling in june year 1.
    On the 1st of January year 2 the new budget prices are inserted in SAP as the new standard price / budget price.
    the fields for display are as follows
    <b>table</b>               <b>  field<b>[/b</b>]             <b>   description</b>
    ekko                        ekorg                              pur org
    ekpo                        matnr                              mat no
    makt                        maktx                            mat des
    cawn                       zunspsc                         unspsc code
    mbew                      stprs                              standard price
    mbew                      peinh                               price unit
    mara                        meins                            base unit of measure
    s012                        menge                            purchsed amount of mat
                                                                         in month 1
    s012                       menge                            purchsed amount of mat
                                                                         in month 2
    s012                       menge                            purchsed amount of mat
                                                                         in month 3
    s012                       menge                            purchsed amount of mat
                                                                         in month 4
    s012                       menge                            purchsed amount of mat
                                                                         in month 5
    ekpo                      netpr                               net price on date criteria 1
    ekpo                      peinh                              price unit
    ekpo                      bprme                             order price unit
    ekpo                      netpr                               net price on date criteria 2
    ekpo                      peinh                              price unit
    ekpo                      bprme                             order price unit
    ekpo                      netpr                               net price on date criteria 3
    ekpo                      peinh                              price unit
    ekpo                      bprme                             order price unit
    ekpo                      netpr                               net price on date criteria 4
    ekpo                      peinh                              price unit
    ekpo                      bprme                             order price unit
    ekpo                      netpr                               net price on date criteria 5
    ekpo                      peinh                              price unit
    ekpo                      bprme                             order price unit

    Hi,
    DATA: begin of i_ekpo,
               menge........
               netpr............
               date ..........
              end of i_ekpo.
    Select menge netpr date
              from ekpo
              into table i_ekpo
             where ....
    if sy-subrc = 0.
    LOOP AT i_ekpo.
    v_month = i_ekpo-date+4(2).
    CASE v_month.
    WHEN '01'
      itab-menge1 = i_ekpo-menge.
      itab-menge5 = i_ekpo-menge.
      itab-netpr1 = i_ekpo-netpr.
      itab-netpr5 = i_ekpo-netpr.
    WHEN '02'.
      itab-menge1 = i_ekpo-menge.
      itab-menge5 = i_ekpo-menge.
      itab-netpr1 = i_ekpo-netpr.
      itab-netpr5 = i_ekpo-netpr.
    WHEN '03'.
      itab-menge1 = i_ekpo-menge.
      itab-menge5 = i_ekpo-menge.
      itab-netpr1 = i_ekpo-netpr.
      itab-netpr5 = i_ekpo-netpr.
    WHEN '12'.
      itab-menge1 = i_ekpo-menge.
      itab-menge5 = i_ekpo-menge.
      itab-netpr1 = i_ekpo-netpr.
      itab-netpr5 = i_ekpo-netpr.
    ENDCASE.
    APPEND itab.
    ENDLOOP.
    Please be more specific with some sample outputs how is should be.

  • Get 15 mins back time from current time (pls help writing query)

    Dear all,
    I need to write a query that gives time 15 mins before the current time.
    I need to calculate hits on a website for last 15 mins.
    Kindly help writing this query.
    Regards, Imran

    select sysdate - 15/(60*24)
    from dual;
    Regards
    Asif Kabir

Maybe you are looking for