Inline views / view merge slowing the query
I have a tool generated query. This query uses inline views. The individual view return data under a second but final query is taking 10min +. any suggestion.
I tried /*+ NO_MERGE(D1,D2,D3,D4)*/ but to no help.
TIA.
SELECT /*+ NO_MERGE(D1,D2,D3,D4)*/DISTINCT d4.c5 AS c1, d2.c14 AS c2,
d3.c8 AS c3, d2.c8 AS c4,
d2.c9 AS c5, d2.c10 AS c6,
d2.c11 AS c7, d2.c12 AS c8,
d2.c13 AS c9
FROM (vv_d1) d1,
(vv_d2) d2,
(vv_d3) d3,
(vv_d4) d4
WHERE ( NVL (d1.c1, 'q') =
NVL (d2.c14, 'q')
AND NVL (d1.c1, 'z') =
NVL (d2.c14, 'z')
AND NVL (d1.c3, 'q') =
NVL (d2.c12, 'q')
AND NVL (d1.c3, 'z') =
NVL (d2.c12, 'z')
AND NVL (d1.c6, 'q') =
NVL (d2.c9, 'q')
AND NVL (d1.c6, 'z') =
NVL (d2.c9, 'z')
AND NVL (d1.c4, 'q') =
NVL (d2.c10, 'q')
AND NVL (d1.c4, 'z') =
NVL (d2.c10, 'z')
AND NVL (d1.c5, 8) =
NVL (d2.c13, 8)
AND NVL (d1.c5, 9) =
NVL (d2.c13, 9)
AND NVL (d1.c1, 'q') =
NVL (d4.c6, 'q')
AND NVL (d1.c1, 'z') =
NVL (d4.c6, 'z')
AND NVL (d1.c1, 'q') =
NVL (d3.c11, 'q')
AND NVL (d1.c1, 'z') =
NVL (d3.c11, 'z')
AND NVL (d1.c2, 88.0) =
NVL (d3.c9, 88.0)
AND NVL (d1.c2, 99.0) =
NVL (d3.c9, 99.0)
AND NVL (d1.c3, 'q') =
NVL (d3.c10, 'q')
AND NVL (d1.c3, 'z') =
NVL (d3.c10, 'z')
AND NVL (d1.c7, 'q') =
NVL (d2.c11, 'q')
AND NVL (d1.c7, 'z') =
NVL (d2.c11, 'z')
)
And the Oracle version number, to three decimal places is?
Post EXPLAIN PLAN output created using dbms_xplan
http://www.psoug.org/reference/explain_plan.html
Similar Messages
-
Does an inline view execute before the rest of the select?
Hi,
The O'Reilly book Mastering Oracle Sql defines an inline view simply as a
subquery in a select FROM clause. This conforms to the definitions in
the Oracle 9i and 10g docs.
But unlike the Oracle docs, the O'Reilly book says the inline view is,
like a WITH clause, executed before the rest of the query. I can't see
how this can be done unless the inline view makes no reference to
other tables joined in the FROM clause.
Is there a species of inline view in 9i/10g that IS restricted as above -
no refs to other tables in the FROM clause - and what is it called?
Thanks for any help.
Ken QuiriciAs explained above, Oracle can choose to merge the query if feasible to do so. Look at the two queries and their plans below. The plan in second query changes to creating a temporary VIEW since in that case, Oracle is unable to perform the merge:
SQL> select *
2 from scott.emp e,
3 (select * from scott.dept d where d.deptno = 10) dd
4 where
5 e.deptno = dd.deptno
6 /
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO DEPTNO DNAME LOC
7782 CLARK MANAGER 7839 09-JUN-1981 2450 10 10 ACCOUNTING NEW YORK
7839 KING PRESIDENT 17-NOV-1981 5000 10 10 ACCOUNTING NEW YORK
7934 MILLER CLERK 7782 23-JAN-1982 1300 10 10 ACCOUNTING NEW YORK
3 rows selected.
Execution Plan
Plan hash value: 3570059291
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 3 | 171 | 2 (0)| 00:00:01 |
| 1 | NESTED LOOPS | | 3 | 171 | 2 (0)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| DEPT | 1 | 20 | 1 (0)| 00:00:01 |
|* 3 | INDEX UNIQUE SCAN | PK_DEPT | 1 | | 0 (0)| 00:00:01 |
| 4 | TABLE ACCESS BY INDEX ROWID| EMP | 3 | 111 | 1 (0)| 00:00:01 |
|* 5 | INDEX RANGE SCAN | IDX_EMP_DEPTNO | 3 | | 0 (0)| 00:00:01 |
SQL> select *
2 from scott.emp e,
3 (select * from scott.dept d where d.deptno = 10 and rownum > 0) dd
4 where
5 e.deptno = dd.deptno
6 /
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO DEPTNO DNAME LOC
7782 CLARK MANAGER 7839 09-JUN-1981 2450 10 10 ACCOUNTING NEW YORK
7839 KING PRESIDENT 17-NOV-1981 5000 10 10 ACCOUNTING NEW YORK
7934 MILLER CLERK 7782 23-JAN-1982 1300 10 10 ACCOUNTING NEW YORK
3 rows selected.
Execution Plan
Plan hash value: 1670713873
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 5 | 280 | 2 (0)| 00:00:01 |
| 1 | NESTED LOOPS | | 5 | 280 | 2 (0)| 00:00:01 |
| 2 | VIEW | | 1 | 19 | 1 (0)| 00:00:01 |
| 3 | COUNT | | | | | |
|* 4 | FILTER | | | | | |
| 5 | TABLE ACCESS BY INDEX ROWID| DEPT | 1 | 20 | 1 (0)| 00:00:01 |
|* 6 | INDEX UNIQUE SCAN | PK_DEPT | 1 | | 0 (0)| 00:00:01 |
| 7 | TABLE ACCESS BY INDEX ROWID | EMP | 5 | 185 | 1 (0)| 00:00:01 |
|* 8 | INDEX RANGE SCAN | IDX_EMP_DEPTNO | 5 | | 0 (0)| 00:00:01 |
SQL> disconnect
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL>
can it, in it's WHERE clause, reference other tables in the FROM clause?No. it cannot. but as said above, tha may not stop Oracle from merging the queries.
SQL> select *
2 from scott.emp e,
3 (select * from scott.dept d where d.deptno = 10 and e.sal > 1000) dd
4 where
5 e.deptno = dd.deptno
6 /
(select * from scott.dept d where d.deptno = 10 and e.sal > 1000) dd
ERROR at line 3:
ORA-00904: "E"."SAL": invalid identifier
SQL> -
Oracle View that stores the Query execution time
Hi Gurus
i m using Oracle 10G in Unix. I wudiold like to know which Data dictionary view stores the execution of a query. If it is not stored then hw to find the query execution time other than (Set timing on) command. What is the use of elapsed time and what is the difference between execution time and elapsed time? How to calculate the execution time of a query.
THanks
RamIf you have a specific query you're going to run in SQL*Plus, just do
a 'set timing on' before you execute the query.
If you've got application SQL coming in from all over the place, you can
identify specific SQL in V$SQL/ and look at ELAPSED_TIME/EXECUTIONS
to get an average elapsed time.
If you've got an application running SQL, and you need to know the
specific timing of a specific execution (as opposed to an average),
you can use DBMS_SUPPORT to set trace in the session that your
application is running in, and then use TkProf to process the resulting
trace file. -
Inline views versus subqueries
How are inline views different form subqueries?
For example:
(1) inline views execute once but subqueries can execute many times in a SQL statement.
Any other points of differentiation?You cant compare them. Inlineview is a kind of Sub Query.
Generally a Sub Query can be defined as a Query withing a Query.
If the Query occurs in the FROM clause then its called Inline View.
If the Query occurs in the SELECT list without any reference to the parent query its called Scalar Sub Query.
If the Query occurs in the WHERE clause by maping it to the parent query then its called Correlated Query. -
On Oracle 11.2, our application uses a "lot" of inline views.
Not knowing much about the benefits or advantages to using inline views, I wondered a few things about the use of them.
First, When I look in OEM, SQL Monitoring, I noticed that queries on inline views that have tables with parallelism set, the queries on inline views do not appear to be using parallelism on the inner query. Or, perhaps they are, but I'm not able to see that they are. How can I tell if they are?
If they are not, would it be necessary to use a hint to use parallelism?
So what are the advantages of using inline views?
I would assume they would use more PGA and/or temp tablespace, but that doesn't seem to be the case in our database (or at least it is not causing any impact that I can tell).974632 wrote:
So what are the advantages of using inline views?
I would assume they would use more PGA and/or temp tablespace, but that doesn't seem to be the case in our database (or at least it is not causing any impact that I can tell).A critical point is whether the inline view can be merged into the calling query. As a general rule, if the view can be merged then the query will be more efficient than if it cannot be. A non-mergeable view has to be instantiated as a memory structure before the calling query can run against it. consider these examples:orcl>
orcl> set autot on exp
orcl> select count(ename) from (select ename from emp);
COUNT(ENAME)
14
Execution Plan
Plan hash value: 2083865914
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 6 | 4 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 6 | | |
| 2 | TABLE ACCESS STORAGE FULL| EMP | 14 | 84 | 4 (0)| 00:00:01 |
orcl> select count(ename) from (select distinct ename from emp);
COUNT(ENAME)
14
Execution Plan
Plan hash value: 1851925981
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 7 | 5 (20)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 7 | | |
| 2 | VIEW | | 14 | 98 | 5 (20)| 00:00:01 |
| 3 | HASH UNIQUE | | 14 | 84 | 5 (20)| 00:00:01 |
| 4 | TABLE ACCESS STORAGE FULL| EMP | 14 | 84 | 4 (0)| 00:00:01 |
orcl>The first query was merged, the second was not: the DISTINCT makes merging impossible, because Oracle cannot be certain that there are no duplicate names. But if I add a unique and not null constraints:orcl> alter table emp add constraint ename_uk unique(ename);
Table altered.
orcl> alter table emp modify ename not null;
Table altered.
orcl> select count(ename) from (select distinct ename from emp);
COUNT(ENAME)
14
Execution Plan
Plan hash value: 1457629042
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 1 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | INDEX FULL SCAN| ENAME_UK | 14 | 1 (0)| 00:00:01 |
orcl>now the inline view is merged (and happens to use the index). This trivial example illustrates how important it is to know and understand your data. If there are no duplicates or no nulls, tell Oracle this. And one of my pet hates: lazy programmers who use aggregations or distinct because they don't know if there are duplicates, and so don't bother to handle them properly.
John Watson
Oracle Certified Master DBA
http://skillbuilders.com -
How to implement Inline Views in ODI?
Hi,
How to implement the following query (inline view) in ODI?
Query:
SELECT *
FROM Table_one t1,
(SELECT * FROM Table_two (includes some where conditions) t2
WHERE conditions;
How to set the conditions at the table level (not at the interface level) i.e., How to set the conditions used in Sub Query Table_two in ODI?
Thanks in Advance,
-Vencythere is no native way to use hierarchical queries.
you will have to modify KM
It depends on your exact needs. -
how it work can any body give me proper guide line about inline view
If you are asking the definition of an "inline query", I can give you a simple example. Consider the following view:
create or replace view MyView as
select 'test' as test from Dual
select MyView.*
from MyViewThe following is the "inline view" version of the same query:
select MyInlineView.*
from (select 'test' as test from Dual) MyInlineViewI hope it helps you...
Best regards.
Elyo Ravuna -
Set view criteria on af:query choice LOV field
i have an af:query. one of the fields is a choice. the LOV for the choice come from a VO. i need to set view criteria for the query for the LOV for the choice. that is, the query for the values of the choice requires view criteria.
moreover, that search criteria is only known by the view. because the hooks for the choice are set up entirely in the model, i don't see how it would ever be possible to use values from the view to define the query for the LOV for the choice.
any ideas?Assuming that you can have a method at the AM level that sets the viewCriteria for your VO, you can drag this method to the page flow to be executed before you go into the query page - this will set the right condition for the list that needs to populate the LOV.
Then the query component can use that VO as an LOV like this:
http://blogs.oracle.com/shay/2009/12/adf_query_with_parameters_and_1.html -
Providing access to Variables in the Query Designer
Greetings experts and fellow consultants,
I have a simple question, did a search and did not come up with much of an answer. Currently, we have a system with a role for BI Power Users in order for them to create ad-hoc queries. An issue we found was that these power users were not able to view variables within the query designer:
Under the "Characteristic Restrictions" pane, the variables show up as (Display Not Allowed) under their associated InfoObjects. This is presenting an issue (understandably) and I would like to provide access for these power users to see the variables.
My question is, are there any circumstances where I would want to restrict which variables are shown to the power user? Right now, I plan to allow display access to all variables (via S_RS_COMP+S_RS_COMP1 for those informed on Security). Just trying to brainstorm on whether there might be scenerios where I would want to hide certain variables.
Many thanks to all opinions, as always!Suresh, in my above post I knew how to enable this. I just wanted to know in regards to security whether there were any exposures. Apparently, I could not find any and the changes went through without issue. The way you enable display of variables in the Query Designer is the following:
S_RS_COMP:
RSINFOAREA '*'
RSINFOCUBE '*'
RSZCOMPTP 'VAR'
ACTVT '03'
S_RS_COMP1:
RSZCOMPTP 'VAR'
RSZCOMPID '*'
RSZOWNER '*'
ACTVT '03'
Hope this helps. Of course, adjust the field values are you see fit but the minimum requirement is that RSZCOMOPTP 'VAR' (Variables) and ACTVT '03' (Display). -
hi
I am keep receiving this message in central administration running server in event viewer
DiscoverSQL2005DBEngineDiscovery.vbs : The Query 'select * from __NAMESPACE where Name ='ComputerManagement'' returned an invalid result set. Please check to see if this is a valid WMI Query.. Object required
adilHi adil,
It seems to be not related to SharePoint issue, I find a similar error post from Operations Manager forum you can take a look
Also another below article of basic troubleshooting of discovery scripts for your reference.
And for the further better assistance regarding this issue, you may want to post Operations Manager forum here.
http://social.technet.microsoft.com/Forums/systemcenter/en-US/21e9de85-5cbc-4217-8d9b-921e13dc88dc/sql-mp-issues-with-discovery-vbs-scripts?forum=operationsmanagermgmtpacks
http://blogs.technet.com/b/kevinholman/archive/2010/03/09/basic-troubleshooting-of-discovery-scripts.aspx
Thanks
Daniel Yang
TechNet Community Support -
SSRS 2008 R2 is extremely slow. The query runs in less than a second in the dataset designer but if you try to view the report it takes over 10 minutes. I have read this is a bug in SSRS 2008 R2. We installed the most recent patches and
service packs. Nothing we've done so far has fixed it and I see that I'm not the only person with this problem. However I don't see any answers either.Hi Kim Sharp,
According to your description that when you view the report it is extremely slow in SSRS 2008 R2 but it is very fast when execute the query in dataset designer, right?
I have tested on my local environment and can‘t reproduce the issue. Obviously, it is the performance issue, rendering performance can be affected by a combination of factors that include hardware, number of concurrent users accessing reports, the amount
of data in a report, design of the report, and output format. If you have parameters in your report which contains many values in the list, the bad performance as you mentioned is an known issue on 2008 R2 and already have the hotfix:
http://support.microsoft.com/kb/2276203
Any issue after applying the update, I recommend you that submit a feedback at https://connect.microsoft.com/SQLServer/
If you don’t have, you can do some action to improve the performance when designing the report. Because how you create and update reports affects how fast the report renders.
Actually, the Report Server ExecutionLog2 view contains reports performance data. You could make use of below query to see where the report processing time is being spent:
After you determine whether the delay time is in data retrieval, report processing, or report rendering:
use ReportServer
SELECT TOP 10 ReportPath,parameters,
TimeDataRetrieval + TimeProcessing + TimeRendering as [total time],
TimeDataRetrieval, TimeProcessing, TimeRendering,
ByteCount, [RowCount],Source, AdditionalInfo
FROM ExecutionLog2
ORDER BY Timestart DESC
Use below methods to help troubleshoot issues according to the above query result :
Troubleshooting Reports: Report Performance
Besides this, you could also follow these articles for more information about this issue:
Report Server Catalog Best Practices
Performance, Snapshots, Caching (Reporting Services)
Similar thread for your reference:
SSRS slow
Any problem, please feel free to ask
Regards
Vicky Liu -
Tuning query with inline views
Hi!
I have a performance problem with the following query. I try to combine v1 and v2 into one inline view but because of the recursive design of the tables workflow and workflow_node it didn't work.
Does anybody has an idea for tuning this query?
SELECT distinct v1.u_protocol_id
FROM ( SELECT workflow_node.workflow_id,u_protocol.u_protocol_id
FROM workflow_node,workflow,U_protocol
WHERE workflow.workflow_id=workflow_node.workflow_id
AND u_protocol.u_protocol_id = workflow_node.parameter_2
AND workflow_node.workflow_node_type_id=17
AND workflow.workflow_node_type_id=42
) v1,
( SELECT workflow_node.workflow_id,test_template.test_template_id
FROM workflow_node,test_template
WHERE test_template.test_template_id = workflow_node.template
AND workflow_node.order_number = 1
AND workflow_node.workflow_node_type_id=42
) v2,
( SELECT aliquot.aliquot_id,test_template.test_template_id
FROM aliquot,test,test_template
WHERE aliquot.aliquot_id = test.aliquot_id
AND test.test_template_id = test_template.test_template_id
) v3
WHERE v1.workflow_id = v2.workflow_id
AND v2.test_template_id= v3.test_template_idI have found a script (utlxplan.sql) for creating the plan_table so here it is
SQL> @c:\utlxplan.sql;
Table created.
SQL> EXPLAIN PLAN FOR SELECT distinct v1.u_protocol_id
2 FROM ( SELECT workflow_node.workflow_id,u_protocol.u_protocol_id
3 FROM lims_sys.workflow_node,lims_sys.workflow,lims_sys.U_protocol
4 WHERE workflow.workflow_id=workflow_node.workflow_id
5 AND u_protocol.u_protocol_id = workflow_node.parameter_2
6 AND workflow_node.workflow_node_type_id=17
7 AND workflow.workflow_node_type_id=42
8 ) v1,
9 ( SELECT workflow_node.workflow_id,test_template.test_template_id
10 FROM lims_sys.aliquot,lims_sys.test,lims_sys.workflow_node,lims_sys.test_template
11 WHERE aliquot.aliquot_id = test.aliquot_id
12 AND test.test_template_id = test_template.test_template_id
13 AND test_template.test_template_id = workflow_node.template
14 ) v2
15 WHERE v1.workflow_id = v2.workflow_id
16 /
Explained.
SQL> SELECT * FROM TABLE(dbms_xplan.display);
PLAN_TABLE_OUTPUT
| Id | Operation | Name |
Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | |
PLAN_TABLE_OUTPUT
| | |
| 1 | SORT UNIQUE | |
| | |
| 2 | FILTER | |
| | |
| 3 | NESTED LOOPS | |
| | |
PLAN_TABLE_OUTPUT
| 4 | NESTED LOOPS | |
| | |
| 5 | NESTED LOOPS | |
| | |
| 6 | NESTED LOOPS | |
| | |
| 7 | NESTED LOOPS | |
| | |
PLAN_TABLE_OUTPUT
| 8 | NESTED LOOPS | |
| | |
| 9 | TABLE ACCESS BY INDEX ROWID| WORKFLOW |
| | |
|* 10 | INDEX RANGE SCAN | FK_WORKFLOW_WORKFLOW_NODE_TYPE |
| | |
| 11 | TABLE ACCESS BY INDEX ROWID| WORKFLOW_NODE |
PLAN_TABLE_OUTPUT
| | |
| 12 | AND-EQUAL | |
| | |
|* 13 | INDEX RANGE SCAN | FK_WORKFLOW_NODE_WORKFLOW |
| | |
|* 14 | INDEX RANGE SCAN | FK_WORKFLOW_NODE_NODE_TYPE |
| | |
PLAN_TABLE_OUTPUT
| 15 | TABLE ACCESS BY INDEX ROWID | U_PROTOCOL |
| | |
|* 16 | INDEX UNIQUE SCAN | PK_U_PROTOCOL |
| | |
| 17 | TABLE ACCESS BY INDEX ROWID | WORKFLOW_NODE |
| | |
|* 18 | INDEX RANGE SCAN | FK_WORKFLOW_NODE_WORKFLOW |
| | |
PLAN_TABLE_OUTPUT
| 19 | TABLE ACCESS BY INDEX ROWID | TEST_TEMPLATE |
| | |
|* 20 | INDEX UNIQUE SCAN | PK_TEST_TEMPLATE |
| | |
| 21 | TABLE ACCESS BY INDEX ROWID | TEST |
| | |
|* 22 | INDEX RANGE SCAN | FK_TEST_TEST_TEMPLATE |
PLAN_TABLE_OUTPUT
| | |
| 23 | TABLE ACCESS BY INDEX ROWID | ALIQUOT |
| | |
|* 24 | INDEX UNIQUE SCAN | PK_ALIQUOT |
| | |
| 25 | INDEX UNIQUE SCAN | PK_OPERATOR_GROUP |
| | |
PLAN_TABLE_OUTPUT
| 26 | INDEX UNIQUE SCAN | PK_OPERATOR_GROUP |
| | |
| 27 | INDEX UNIQUE SCAN | PK_OPERATOR_GROUP |
| | |
| 28 | INDEX UNIQUE SCAN | PK_OPERATOR_GROUP |
| | |
| 29 | INDEX UNIQUE SCAN | PK_OPERATOR_GROUP |
| | |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
10 - access("SYS_ALIAS_5"."WORKFLOW_NODE_TYPE_ID"=42)
13 - access("SYS_ALIAS_5"."WORKFLOW_ID"="WORKFLOW_NODE"."WORKFLOW_ID")
14 - access("WORKFLOW_NODE"."WORKFLOW_NODE_TYPE_ID"=17)
PLAN_TABLE_OUTPUT
16 - access("SYS_ALIAS_4"."U_PROTOCOL_ID"=TO_NUMBER("WORKFLOW_NODE"."PARAMETER
_2"))
18 - access("WORKFLOW_NODE"."WORKFLOW_ID"="WORKFLOW_NODE"."WORKFLOW_ID")
20 - access("SYS_ALIAS_1"."TEST_TEMPLATE_ID"="WORKFLOW_NODE"."TEMPLATE")
22 - access("SYS_ALIAS_2"."TEST_TEMPLATE_ID"="SYS_ALIAS_1"."TEST_TEMPLATE_ID")
24 - access("SYS_ALIAS_3"."ALIQUOT_ID"="SYS_ALIAS_2"."ALIQUOT_ID")
Note: rule based optimization -
Can You Explain This SQL Query - Inline View Included
The query is taken from "Oracle Database 10g: SQL Fundamentals II" page 3-7 (chapter 3)
I do not fully understand the following query:
SELECT a.last_name, a.salary, a.department_id, b.salavg
FROM employees a, (SELECT department_id,
AVG(salary) salavg
FROM employees
GROUP BY department_id) b
WHERE a.department_id = b.department_id
AND a.salary > b.salavg;
The inline view can return several records. Can you please tell me in step by step how does this work. I understand the concept of join tables and aliases, etc. I just need to know the mechanism of this code.
Thanksuser11164565 wrote:
The query is taken from "Oracle Database 10g: SQL Fundamentals II" page 3-7 (chapter 3)
I do not fully understand the following query:
SELECT a.last_name, a.salary, a.department_id, b.salavg
FROM employees a, (SELECT department_id,
AVG(salary) salavg
FROM employees
GROUP BY department_id) b
WHERE a.department_id = b.department_id
AND a.salary > b.salavg;
The inline view can return several records. Can you please tell me in step by step how does this work. I understand the concept of join tables and aliases, etc. I just need to know the mechanism of this code.
The query is returning the last name, salary , department and average salary of all the departments where salary is greater than the average salary.
HTH
Aman.... -
Need help with SQL Query with Inline View + Group by
Hello Gurus,
I would really appreciate your time and effort regarding this query. I have the following data set.
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
Please Ignore '----', added it for clarity
I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
The query should return the following data set
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
The following is my query. I am kind of lost.
select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
from (
select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
from INVOICE
group by sequence_id,check_date, check_number, invoice_number, vendor_number
) A, INVOICE B
where A.sequence_id = B.sequence_id
Thanks,
NickIt looks like it is a duplicate thread - correct me if i'm wrong in this case ->
Need help with SQL Query with Inline View + Group by
Regards.
Satyaki De. -
Query works everywhere but Flex: inline views not supported perhaps?
EDIT2: Actually not. It turns out to be a bug in the way Adobe is treating any integer PK column, no matter how it is defined, INT, or INTEGER, as an alias for the rowid in SQlite. This is incorrect. rowid does not always equal the PK value. This causes joins to return the wrong values.
EDIT: turns out to be the use of the absolute value function in the query.
See http://forums.adobe.com/thread/516392
My bread-and-butter query, the one that is the core of my application, uses a UNION query with inline views when doing proximity word-searches. It works beautifully in SQLite returning a resultset in about one second from an over 300MB database, against several tables equijoined, the two biggest tables having close to 4 million rows and 300,000 rows, respectively.
It runs fine in Visual Studio using the .NET provider for SQLite, and also in SQLite Manager 0.5.6 by Mrinal Kant and in other front-ends to SQLite. But the verbatim query returns no rows in Flex and zero rows in the SQLite Admin GUI front-end, which is built on the Flex SQL libraries.
My first thought is that inline views might not be supported in Flex?
Does Flex do what in the Microsoft world is called a "pass-through" query, sending the sql intact through to the back end, or does Flex take the query statement apart and apply the WHERE clause conditions client-side, as Microsoft Access does to support so-called "heterogeneous" joins, i.e. queries that might join tables from, say, SQL Server and Oracle in the same query?EDIT2: Actually not. It turns out to be a bug in the way Adobe is treating any integer PK column, no matter how it is defined, INT, or INTEGER, as an alias for the rowid in SQlite. This is incorrect. rowid does not always equal the PK value. This causes joins to return the wrong values.
EDIT: turns out to be the use of the absolute value function in the query.
See http://forums.adobe.com/thread/516392
My bread-and-butter query, the one that is the core of my application, uses a UNION query with inline views when doing proximity word-searches. It works beautifully in SQLite returning a resultset in about one second from an over 300MB database, against several tables equijoined, the two biggest tables having close to 4 million rows and 300,000 rows, respectively.
It runs fine in Visual Studio using the .NET provider for SQLite, and also in SQLite Manager 0.5.6 by Mrinal Kant and in other front-ends to SQLite. But the verbatim query returns no rows in Flex and zero rows in the SQLite Admin GUI front-end, which is built on the Flex SQL libraries.
My first thought is that inline views might not be supported in Flex?
Does Flex do what in the Microsoft world is called a "pass-through" query, sending the sql intact through to the back end, or does Flex take the query statement apart and apply the WHERE clause conditions client-side, as Microsoft Access does to support so-called "heterogeneous" joins, i.e. queries that might join tables from, say, SQL Server and Oracle in the same query?
Maybe you are looking for
-
Hi Experts, below query is taking a long time, what is the fix to tune this, SELECT aufnr auart kdauf FROM caufv INTO TABLE tl_caufv WHERE kdauf EQ i_viqmel-vbeln.
-
How do i get full screen airplay mirroring
Ive downloaded ML but when i launch airplay mirroring it doesn't fill the full widescreen of a TV. can anyone help?
-
I am using an action servlet to call a UseCase Object which calls a Data Access Object and shoot data back to the Servlet and then completes it's task. When when I go to call the UseCase it tells me my method does not exist. Anybody have any ideas. T
-
I'm new on these forums and was just wondering if there was any way to get just quicktime installed without having to go through the hassle of installing the itunes S**TE? If anyone knows of the best way of doing this then I would like to know asap b
-
My late 2010 Macbook Air fails to start up
I took my MacBook Air (late 2010 models) with me on my travels to Asia. A few days into my trip, I went back to my laptop. After opening the lid, the Macbook started up from the hibernation state as normal. Whilst I was typing in my password, the lap