Difference in queries

can someone let me know difference between following queries.. why they return different results for the 4th column.
SELECT      CUSTOMER.BILL_CYCLE,
CUSTOMER.PARTITION_ID,
COUNT(*),
(select count(1)
from Subscriber S , Customer C
where S.customer_id = C.customer_id
and S.sub_status='A'
and C.BILL_CYCLE = Customer.BILL_CYCLE
and C.PARTITION_ID = CUSTOMER.PARTITION_ID)
FROM CUSTOMER
group by BILL_CYCLE, PARTITION_ID
SELECT bill_cycle, partition_id, COUNT (*),SUM (subs_per_customer)
FROM (SELECT /*+ use_hash(c s) parallel(c,4) */
bill_cycle, partition_id, c.customer_id,
COUNT (DECODE (s.subscriber_no, NULL, 0, 1)) subs_per_customer
FROM subscriber s, customer c
WHERE s.customer_id(+) = c.customer_id AND s.sub_status(+) = 'A'
GROUP BY bill_cycle, partition_id, c.customer_id)
GROUP BY bill_cycle, partition_id

Try something like this. And just dont say its slow. Paste the explain plan and the table structure also.
SQL> create table customer(bill_cycle number, partition_id number, customer_id number);
Table created.
SQL> insert into customer values (1,1,1);
1 row created.
SQL> insert into customer values (1,1,2);
1 row created.
SQL> insert into customer values (1,1,3);
1 row created.
SQL> insert into customer values (1,1,4);
1 row created.
SQL> insert into customer values (1,1,5);
1 row created.
SQL> create table subscriber(customer_id number, sub_status char(1));
Table created.
SQL> insert into subscriber values (1,'A');
1 row created.
SQL> insert into subscriber values (2,' ');
1 row created.
SQL> insert into subscriber values (3,'A');
1 row created.
SQL> insert into subscriber values (4,' ');
1 row created.
SQL> insert into subscriber values (5,'A');
1 row created.
SQL> commit
  2  /
Commit complete.
SQL>  SELECT bill_cycle,
  2     partition_id,
  3     count(*) cnt,
  4     sum(cnt) sm
  5     FROM (SELECT c.bill_cycle,
  6             c.partition_id,
  7             (SELECT count(1)
  8                FROM subscriber s
  9               WHERE s.customer_id  = c.customer_id
10                 AND s.sub_status   = 'A') cnt
11        FROM customer c)
12    GROUP BY bill_cycle,
13     partition_id
14  /
BILL_CYCLE PARTITION_ID        CNT         SM
         1            1          5          3Edited by: Karthick_Arp on Oct 15, 2008 11:59 PM
Corrected the typo

Similar Messages

  • Difference between queries 0PUR_C01_Q0022 and 0BBP_C01_Q020

    Hi Experts,
    Can anyone help me in bringing out the difference between the query 0PUR_C01_Q0022 and 0BBP_C01_Q020.The description of both says that the query is meant for purchase order without contract,but fetches data from different cubes.so what is the difference between them.
    Please dont give me any links in help.sap,I have read enough.
    Regards,
    Meera

    Which data refers to the purchase order an organisation receives
    That tends to be for sales - so CRM and R3 SD
    and the one which the orgn raises for procurement
    thats SRM and R3 MM

  • How to ensure that the queries are in sync between Web browser and Bex

    Hi All,
    I am struck with this issue for more than a month.  Can someone help me in understanding this and resolving?  Thanx!!
    "Ad hoc reports showing in web browser but not showing in BeX, if added to BeX then appearing twice on web browser"
    Edited by: RAMABHOTLA SHANKER on May 21, 2009 2:09 PM

    Hi,
    There is no difference in queries elements between BEx and Web Browser, the adhoc queries/analysis/variants you create in web analyser doesn't get save back to BI server; its saving only in EP server.
    Where as if you save any query view in BEx analyzer can also be viewed in Web analyzer, thats the reason you are able to see both of them. But actually meta data for both the query views are different.
    Hope it clarifies.
    Regards,
    Surya.

  • How to compare the query definiation of two or more queries?

    HI Folks.
    I am attempting to determine if there is a method by which I can compare query definination of two or more queries or shows me the differences between queries. 
    Transaction RSRTQ only give the query details of single query at a time and doesnot do a comparison.
    Please let me know a method to undertake this?
    Thanks
    Uday

    There is no straight way of doing this:
    I normally open the definitions in 2 sessions and compare them manually.
    Hope this helps

  • Questions - example queries

    Hello Everyone,
    We are learning delete examples:
    We have questions differences between queries:
    Begin Example <<<<<<<<<<<<<<<<The following statement deletes from the sample table hr.employees purchasing clerks whose commission rate is less than 10%:
    DELETE FROM employees
    WHERE job_id = 'SA_REP'
    AND commission_pct < .2;
    The following statement has the same effect as the preceding example, but uses a subquery:
    DELETE FROM (SELECT * FROM employees)
    WHERE job_id = 'SA_REP'
    AND commission_pct < .2;
    End Example <<<<<<<<<<<<<<<<If you have knew Pro and Con between above queries, please share with us.
    Thanks in advance,
    S!G

    The subquery is useless syntax in this case. The statements produce the identical explain plan (notice the plan hash values):
    SQL> explain plan for
      2  DELETE FROM employees
      3  WHERE job_id = 'SA_REP'
      4  AND commission_pct < .2;
    Explained.
    SQL> @xp
    PLAN_TABLE_OUTPUT
    Plan hash value: 3559291088
    | Id  | Operation          | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | DELETE STATEMENT   |           |     3 |   147 |     3   (0)| 00:00:01 |
    |   1 |  DELETE            | EMPLOYEES |       |       |            |          |
    |*  2 |   TABLE ACCESS FULL| EMPLOYEES |     3 |   147 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - filter("JOB_ID"='SA_REP' AND "COMMISSION_PCT"<.2)
    14 rows selected.
    SQL> explain plan for
      2  DELETE FROM (SELECT * FROM employees)
      3  WHERE job_id = 'SA_REP'
      4  AND commission_pct < .2;
    Explained.
    SQL> @xp
    PLAN_TABLE_OUTPUT
    Plan hash value: 3559291088
    | Id  | Operation          | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | DELETE STATEMENT   |           |     3 |   147 |     3   (0)| 00:00:01 |
    |   1 |  DELETE            | EMPLOYEES |       |       |            |          |
    |*  2 |   TABLE ACCESS FULL| EMPLOYEES |     3 |   147 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - filter("EMPLOYEES"."JOB_ID"='SA_REP' AND
                  "EMPLOYEES"."COMMISSION_PCT"<.2)
    15 rows selected.

  • Authorizations set for one query different from another query

    Hello All,
    Here is my requirements for 2 differents BW queries :
    For some particular user
    1-Query A have to show data from company code 1 & company code 2
    2-Query B have to show data from company code 1
    How can I manage such authorization with RSEACADMIN ?
    I was thinking of using infoObject 00TCTQUERID .
    What do you suggest ?
    I will try to do some test and come back later with my tests results.
    Regards
    Catherine

    Hello,
    Thanks for your help on this. I will not use query restrictions with S_RS_COMP or  S_RS_COMP1.
    Also, Query A and query B are created on the same cube, so I cannot use 2 differents analysis authorization. I wish I was able to say this analysis authorization applies to query A and this analysis authorizations apply to query B.
    So far, this is not possible.
    I think my only possibility is to create a multiprovider and copy query B to this multiprovider. Then I will create 2 differents analysis authorizations for each cube.
    I don't think that I will find a better solution.
    I will test it asap.
    Regards
    C.

  • Query execution slow for the first time...

    I am new to Oracle sql.
    I have a query whose performance is very slow for the first time, but on subsequent executions its fast. When executed for the first time it is taking around 45 seconds and on subsequent executions, 600 milliseconds.
    Is there a specific reason for this to happen. I am calling this query from my java code using a prepare statement.

    Are the differences in queries solely in the where clause? If so can you parameterize the query and use bind variables instead so the only difference from one query to the next is the values of the bind variables? Using bind variables in your queries will enable the parser to reuse the already parsed queries even when the bound values differ.
    Also there may be other optimizations that can be made to either your query or the tables that it is querying against to improve your performance. To be able to improve your queries performance you need to understand how it's accessing the database.
    See Rob's thread on query optimization [When your query takes too long |http://forums.oracle.com/forums/thread.jspa?threadID=501834&start=0&tstart=0] for a primer on optimizing your query.

  • Query/queryview

    Hi ,
    Our client has decided to re-create all queries with new names in development,test them and move to Production.
    The information from user is that if its a queryview,it should be created directly in Production with new name.
    All the webtemplates which are using these old queries and queryviews should be updated with new queries and new queryviews.
    I have few doubts about following:
    1.How to identify if its a query or queryview?
    2.is creating a queryview same as creating a query in query designer or is there any different steps involved?
    3.when we are in WAD3.5 OR 7.0 and trying to update webtemplates,how do we identify if a webitem in a template is based on Query or Queryview because I just see name and feel confused about how to identify if its a query or queryview?
    Thanks for your guidance.
    Regards.

    Hi Polintram,
    Just to get some additional background - you mention that all queries have been recreated in DEV - so, none of the original query views have been recreated - correct? If the query views are also recreated in DEV, once you transport the queries, the query views come with them. IF not, and you are going to create query views in PROD>
    If you want to see the difference between queries and query views - you would have to go to the appropriate tables that store the queries and query views.
    query views are only created from the user screen - once the query is executed, then the user can change the query based on personal needs, then save as a query view - this will show in a different area and you can execute a query view by going to NEW ANALYSIS >> switch to VIEW >> then SAVE. You could also, use the context menu in the query Right Click > save view > this will save the query as a query view (subset of the query).
    you don't create query views using the query designer
    The WAD templates are basically for queries - the query view takes on the template that the query (which is the base of the query view is) is using - now, there are some additional detailed approaches to this - for example, if you change the WAD template with some changes to the parameters - for example, show more than 4 columns, or more than the initial 25 rows - the query view will NOT take these changed parameters on but will keep the original template format - so, the base query will show the new parameters but the query view will show the original parameters of the WAD template. I tested this on the 0ANALYSIS_PATTERN template.
    thanks, Pete

  • Whats the difference between these two queries ? - for tuning purpose

    Whats the difference between these two queries ?
    I have huge amount of data for each table. its takeing such a long time (>5-6hrs).
    here whice one is fast / do we have any other option there apart from listed here....
    QUERY 1: 
      SELECT  --<< USING INDEX >>
          field1, field2, field3, sum( case when field4 in (1,2) then 1 when field4 in (3,4) then -1 else 0 end)
        FROM
          tab1 inner join tab2 on condition1 inner join tab3 on condition2 inner join tab4 on conditon3
        WHERE
         condition4..10 and
        GROUP BY
          field1, field2,field3
        HAVING
          sum( case when field4 in (1,2) then 1 when field4 in (3,4) then -1 else 0 end) <> 0;
    QUERY 2:
       SELECT  --<< USING INDEX >>
          field1, field2, field3, sum( decode(field4, 1, 1, 2, 1, 3, -1, 4, -1 ,0))
        FROM
          tab1, tab2, tab3, tab4
        WHERE
         condition1 and
         condition2 and
         condition3 and
         condition4..10
        GROUP BY
          field1, field2,field3
        HAVING
          sum( decode(field4, 1, 1, 2, 1, 3, -1, 4, -1 ,0)) <> 0;
    [pre]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    My feeling here is that simply changing join syntax and case vs decode issues is not going to give any significant improvement in performance, and as Tubby points out, there is not a lot to go on. I think you are going to have to investigate things along the line of parallel query and index vs full table scans as well any number of performance tuning methods before you will see any significant gains. I would start with the Performance Manual as a start and then follow that up with the hard yards of query plans and stats.
    Alternatively, you could just set the gofast parameter to TRUE and everything will be all right.
    Andre

  • Query to get the difference between 2 totals from 2 different queries

    I wanted to know if it is possible to get the difference between 2 totals from 2 different queries. I would explain with an example:
    1st query  - Select sum(homepass) from table 1
    2nd query – select sum(homepass) from table2
    Is it possible to display the difference like-
    Select sum(homepass) from table 1 - sum(homepass) from table2
    I know the above query would gives syntax error but is there a better way or a trick to get the above task accomplished from a single query.
    I hope, my question is clear.
    Please revert with the reply to my query.
    Regards

    tomernitin wrote:
    Try this one also:
    WITH adtn1
    AS
    SELECT 110 val1 FROM dual UNION ALL
    SELECT 100 FROM dual UNION ALL
    SELECT 90  FROM dual UNION ALL
    SELECT 10 FROM dual
    adtn2
    AS
    SELECT 10 val2 FROM dual UNION ALL
    SELECT 20 FROM dual UNION ALL
    SELECT 30  FROM dual UNION ALL
    SELECT 100 FROM dual
    SELECT(Sum(a1.val1)-Sum(a2.val2)) Diff FROM adtn1 a1,adtn2 a2;
    let me know if you still have any doubt.
    Um.... I don't think so. Not with the cartesian join between a1 and 2.

  • Difference between Pre-Calculated Queries in BI 7.0 and BW 3.5

    Hi
    Can somebody tell me the difference between pre-calculated queries (web templates) in BI 7.0 and BW 3.5? Is there any difference in Reporting Agent functionality in creating or scheduling the queries?
    Thanks in advance.

    hi kashi
    u could have searched forum with u r question
    anyway go thru following links
    <b>/community [original link is broken]
    Difference in Delta between BW 3.5 and BI 7.0
    /message/2927917#2927917 [original link is broken]
    How much difference between BW 3.5 and BI 7.0?

  • Create Same  Variable for 2 differents queries

    Hi guru's,
    I try to create one same variable in query designer for differents queries whiche have not the same field. I explain:
    For example, I have one of my query based on a ODS which has a field called EAN but its technical name is RIS_R1007_F57 and I have another query based on another ODS which has also a field called EAN with the following techincal name RIS_EANMD_F1.
    I would like to create a report with 2 tables and each query inside with in the variable screen, a variable which seeks in the both tables.
    Anyone has an idea?
    Thanks in advance for your help.
    Regards,
    Rawizzz.
    Edited by: rahhaoui mohamed on Jan 26, 2010 11:39 AM

    Hi.
    What I understand, is that you have something called EAN and this is stored in two ODS. In each ODS a DIFFERENT characteristic is used to store the EAN info.
    Thus, technically, you got two completely unrelated fields. The fact that they both contain the data for the same "thing" (the EAN), is something you can "tell the system" by creating a characteristic, let's say tech name ZEAN with description "EAN" and then load the values from both char's (RIS_R1007_F57 & RIS_EANMD_F1) into this new char (ZEAN).
    You could do this in different ways, but one way to do this, is to add the ZEAN to BOTH ODS and then in the load to each of the ODS, map the RIS_R1007_F57 to ZEAN and the RIS_EANMD_F1 to ZEAN.
    Now you can create two queries, query 1 on the data from ODS1, where you have RIS_R1007_F57 and ZEAN, and query2 on ODS2, where you have RIS_EANMD_F1 and ZEAN.
    In query1, you use ZEAN to make your restriction/selection, so create a variable on the ZEAN infoobject, ZVAR_1. When you are done, create query2 on the other dataset. Use ZEAN to make your restriction/selection AGAIN. You will find in the variables section the variable ZVAR_1 which you created before. Use it again and finish query2.
    Put both queries in a workbook, maybe on different sheets depending on what you need. Then, set the workbook properties to show the same variable in different queries only once.
    That should work.
    Br
    Jacob

  • Difference of 2 queries

    Will the below query return the difference of the "sum(e.gl_fig)" column from both the queries ?
    select (select sum(e.gl_fig) from rm_gl e where e.as_on_dt <= trunc(to_date('30-NOV-2011'),'Q')- 1) - (select sum(e.gl_fig) from rm_gl e where e.gl_id in (211,212,213,214,215,216,217) and e.as_on_dt = to_date('30-NOV-2011')) current_quarter_amount from dual

    Have you tried it? Did it work?
    It looks like it probably should work, but not easy to read ;-)
    (Would be nice if you had formatted the code and put it within tags...)                                                                                                                                                                                                                                                                                                                                                                       

  • Difference between the queries - help needed.

    I have three tables Plan_Zip,Service_Zip,Plan_Info
    Plan_Zip is the parent table and referenced by Service_Zip
    and Service_Zip is referenced by Plan_Info.
    I have this query:
    select
         sz.ts_nbr,pz.packages_qty,pz.stops_qty
    from
         plan_zip pz, service_zip sz, plan_info pi
    where
         pi.plan_run_nbr = sz.plan_run_nbr and
         sz.service_run_nbr = pz.service_run_nbr and     
         pi.day_plan_nbr = 43027 and
         pi.run_type_nbr = 0 and
         sz.ts_nbr = 1 or sz.ts_nbr = 2
    When I am running the query I am getting so many rows which are identical,
    but when I modified the above query as:
    select
         sz.ts_nbr,pz.packages_qty,pz.stops_qty
    from
         plan_zip pz, service_zip sz, plan_info pi
    where
         pi.plan_run_nbr = sz.plan_run_nbr and
         sz.service_run_nbr = pz.service_run_nbr and     
         pi.day_plan_nbr = 43027 and
         pi.run_type_nbr = 0 and
         (sz.ts_nbr = 1 or sz.ts_nbr = 2)
    I am getting the correct results.
    Please explain me the difference between the above two queries.
    Regards
    Raghu

    Look at the below example
    SQL> create table t
      2  as
      3  select level no, level no1, 0 no2
      4    from dual
      5  connect by level <= 5
      6  /
    Table created.
    SQL> select * from t
      2  /
            NO        NO1        NO2
             1          1          0
             2          2          0
             3          3          0
             4          4          0
             5          5          0
    SQL> select *
      2    from t
      3   where no = 1
      4     and no1 = 1
      5      or no2 = 0
      6  /
            NO        NO1        NO2
             1          1          0
             2          2          0
             3          3          0
             4          4          0
             5          5          0Here what the where condition is telling is no should be 1, no1 should be 1 or no2 is 0. you can read it like this.
    if (no = 1 and no1 = 1) or (no2 = 0)
    then
         true ;
    else
         false;
    end if;so what i does is no2 = 0 is satisfied by all the rows and hence all the rows are returned.
    Next...
    SQL> select *
      2    from t
      3   where no = 1
      4     and (no1 = 1 or no2 = 0)
      5  /
            NO        NO1        NO2
             1          1          0This can be read like this.
    if (no = 1) and (no1 = 1 or no2 = 0)
    then
         true ;
    else
         false;
    end if;Here no = 1 is a must satisfy condition. Once that is satisfied then no1 can be 1 or no2 can be 0 which ever is
    satisfied consider that. So the first condition no=1 is satisfied by only one record and hence that alone is returned.
    Thanks,
    Karthick.

  • What is the difference between Saved views and queries

    Hi all,
    Just i want to know the difference between 2 options in the Bex Analyzer.  Those options are "Queries" and " Saved Views". Please check it out and let me know the difference

    To add to the previous posts, saved views can also be useful when developing web templates. You can create and save one query and then save a number of views from this query, with different layouts, filters etc. web templated can then be developed using the saved views. BW 2004s introduces a whole load of standard functions to switch dataproviders in web templates. Thes can be used to switch between a number of views in a template. I have used this to present selections of key figures, switch navigation states etc.
    Regards
    Peter

Maybe you are looking for

  • "Insufficient Store Credit" message.

    Okay, so I am trying to download an app in the Itunes store that cost's $9.99, however every time I try to download it, Itunes says that I have insuffient store credit, even though I have $10.33, anybody know whats going on here?

  • Each song on my iTunes has a duplicate. How do I delete all duplicates and prevent this from happening again in the future?

    Each song on my iTunes has a duplicate. How do I delete all duplicates and prevent this from happening again in the future?

  • How to delete CT_LONGTEXT?

    Hi, I am having a requirement to delete "Supplier Text" of an item in a Shopping Cart(SRM 7.0) if an assigned supplier is removed. If i delete manually then it is working fine, but i couldn't delete through coding. If i assign new/update the supplier

  • XSQL and namespaces

    I can declare a namespace at the top of an XSQL file and I can set a namespace prefix for ROWSET and ROW tag names but I cannot return namespace-prefixed elements from a SQL query due to the invalidity of the colon character. Can someone please prove

  • How do I fix error code MZCommerce.JmsSendError_message

    When I tried to update Clash of Clans this morning, I got the error, "MZCommerce.JmsSendError_Message." Of course, I went to my computer to try to do the update. When I try it there, I get error code "11111." It will not allow me to update any of my