Difference-conditions (join and a Where Clause)
Hi people,
I need to clearly agree on what a difference exactly when we put any condition in INNER JOIN and the WHERE Clause.
I have tried both way and found the same results. Even in the statistics Plan not much differences. Any help would be appreciated.
As:
1 here, I use filter store in the join condition - Inner
"SELECT i., Gl * Sc1.Item I.
Inner Join Sc1.Part P
On P.Part_Id = I.Part_Id
Inner Join Sc1.Location Gl
On Gl.Location_Id = I.Location_Id
And Gl.Location_Id in (1767, 1747,202,1625)
Inner Join Sc1.Condition C
On C.Condtion_Id = Gl.Condition_Id
Where I.Inactive_Ind = 0
And I.Condition_Id! = 325
2. here I use filter store in Where clause-
SELECT i., Gl * Sc1.Item I
Inner Join Sc1.Part P
On P.Part_Id = I.Part_Id
Inner Join Sc1.Location Gl
On Gl.Location_Id = I.Location_Id
Inner Join Sc1.Condition C
On C.Condtion_Id = Gl.Condition_Id
Where I.Inactive_Ind = 0
and I.LOCATION_ID in (1767, 1747,202,1625)
And I.Condition_Id! = 325
Thank you
Mark
Hello
MarkCooper wrote:
Hi guys,.
To reply to all - I understand.
1. its good practice to use conditions / filter (except CLAUSE) in the WHERE Clause rather Inner join? bon ?
2. now, in my previous example. We could use the location code in where clause as it was in the two tables.
What is the best practice to use the code to location here ( 1 /2) ?
1. here I use filter store in the Inner join condition ( guess the location code is not in the article table)).
"SELECT i., Gl * Sc1.Item I.
Inner Join Sc1.Part P
On P.Part_Id = I.Part_Id
Inner Join Sc1.Location Gl
On Gl.Location_Id = I.Location_Id
And Gl.Location_Id in (1767, 1747,202,1625)
Inner Join Sc1.Condition C
On C.Condtion_Id = Gl.Condition_Id
Where I.Inactive_Ind = 0
And I.Condition_Id! = 325
2. here I use filter store in Where clause (assume that the location code is not in the article table)-
SELECT i., Gl * Sc1.Item I
Inner Join Sc1.Part P
On P.Part_Id = I.Part_Id
Inner Join Sc1.Location Gl
On Gl.Location_Id = I.Location_Id
Inner Join Sc1.Condition C
On C.Condtion_Id = Gl.Condition_Id
Where I.Inactive_Ind = 0
And Gl.Location_Id in (1767, 1747,202,1625)
And I.Condition_Id! = 325
Thank you
If location_id isn't in the item table, then the join condition
On Gl.Location_Id = I.Location_Id
will cause an error.
Once more, it should not affect results or performance if a condition like
Gl.Location_Id in (1767, 1747,202,1625)
is in the clause or the WHERE clause. No matter if it is be a column called location_id in any other table, or if the same column Gl.Location_Id is used in other conditions.
As this condition only refers to a table (GI), I recommend you put it in a WHERE clause, just to make the code clearer.
Yet once, this applies only to the inner joins, not for outer joins and not to CONNECT BY queries.
Tags: Database
Similar Questions
-
left outer join and the where clause for the table to the right
I want to join two tables a and b, where a is a must and b is a result set in option. When I use a left outer join to a to b, I want to achieve:
1. Select a single column, two columns of b (not the join columns)
2 - even if theres no friendly on the join column does not return data from one.
3. If there is a match applies when the criteria on column b (table in option)
so, how can I avoid no_data_found in this case? When I apply where criteria for b, so it does not return the data from one, which is a must.Sounds like a regular outer join to me...
select a.col1, b.col2, b.col2 from tableA a left outer join tableB b on (a.id = b.id and b.colX = 'X')
-
Syntax of UPDATE of Oracle with the JOIN and the WHERE clause
I need to update one of my paintings and can't seem to get the syntax right. I tried 4 different approaches, but does not have a chance. Any help would be greatly appreciated.
Attempt #1: Error: not correctly completed SQL command
UPDATE TESTDTA.F4941
SET TESTDTA.F4941.RSDSTN=TESTDTA.F4981.FHRTDQ,TESTDTA.F4941.RSUMD1=TESTDTA.F4981.FHUOM
FROM TESTDTA.F4941
INNER JOIN TESTDTA.F4981
ON TESTDTA.F4941.RSSHPN = TESTDTA.F4981.FHSHPN
WHERE TESTDTA.F4941.RSSHPN = 647143
AND TESTDTA.F4941.RSDSTN = 0
AND TESTDTA.F4941.RSADDJ > 110365
AND TESTDTA.F4981.FHCGC1 = 'DIS';Try #2: Error report: SQL error: ORA-00904: "TESTDTA." "" F4981 ". "' FHUOM ': invalid identifier 00904. 00000 - '% s: invalid identifier '.
UPDATE (SELECT TESTDTA.F4941
FROM TESTDTA.F4941
INNER JOIN TESTDTA.F4981
ON TESTDTA.F4941.RSSHPN = TESTDTA.F4981.FHSHPN
WHERE TESTDTA.F4941.RSSHPN = 647143
AND TESTDTA.F4941.RSDSTN = 0
AND TESTDTA.F4941.RSADDJ > 110365
AND TESTDTA.F4981.FHCGC1 = 'DIS')
SET TESTDTA.F4941.RSDSTN=TESTDTA.F4981.FHRTDQ,TESTDTA.F4941.RSUMD1=TESTDTA.F4981.FHUOMTry #3: Error report: SQL error: ORA-00904: "TESTDTA." "' F4941 ': invalid identifier 00904. 00000 - '% s: invalid identifier '.
UPDATE (SELECT *
FROM TESTDTA.F4941
INNER JOIN TESTDTA.F4981
ON TESTDTA.F4941.RSSHPN = TESTDTA.F4981.FHSHPN
WHERE TESTDTA.F4941.RSSHPN = 647143
AND TESTDTA.F4941.RSDSTN = 0
AND TESTDTA.F4941.RSADDJ > 110365
AND TESTDTA.F4981.FHCGC1 = 'DIS')
SET TESTDTA.F4941.RSDSTN=TESTDTA.F4981.FHRTDQ,TESTDTA.F4941.RSUMD1=TESTDTA.F4981.FHUOM;Try #4: Error: ORA-00925: Missing keyword 00925. 00000 - "missing IN the keyword"
MERGE TESTDTA.F4941
USING TESTDTA.F4981
ON (TESTDTA.F4941.RSSHPN = TESTDTA.F4981.FHSHPN
AND TESTDTA.F4941.RSSHPN = 647143
AND TESTDTA.F4941.RSDSTN = 0
AND TESTDTA.F4941.RSADDJ > 110365
AND TESTDTA.F4981.FHCGC1 = 'DIS'
)
WHEN MATCHED THEN
UPDATE SET TESTDTA.F4941.RSDSTN=TESTDTA.F4981.FHRTDQ
,TESTDTA.F4941.RSUMD1=TESTDTA.F4981.FHUOM;Finally managed to do work, adding DISTINCT to select. I have pasted the SQL error in Google to begin with. Laughing out loud!
Code snippet work for anyone who comes across this thread...
MERGE INTO TESTDTA. F4941 DST
USING (SELECT DISTINCT TESTDTA. F4941. RSSHPN,
TESTDTA. F4941. RSDSTN,
TESTDTA. F4941. RSUMD1,
TESTDTA. F4941. RSADDJ,
TESTDTA. F4981. FHSHPN,
TESTDTA. F4981. FHRTDQ,
TESTDTA. F4981. FHUOM,
TESTDTA. F4981. FHCGC1
OF TESTDTA. F4941
JOIN INTERNAL TESTDTA. F4981
ON TESTDTA. F4941. RSSHPN = TESTDTA. F4981. FHSHPN
WHERE - TESTDTA. F4941. RSSHPN = 647143 AND
TESTDTA. F4941. RSDSTN = 0
AND TESTDTA. F4941. RSADDJ > 110365
AND TESTDTA. F4981. FHCGC1 = 'SAY') CBC
on (DST. RSSHPN = SRC. FHSHPN)
When matched then update
SET DST. RSDSTN = SRC. FHRTDQ, SUMMER TIME. RSUMD1 = SRC. FHUOM;
Thanks to everyone who helped with this.
-
Group by, with and without where clause
Do I need to use these two interior views to display the results by group by a line? I can get the same result without having to type the same statement select twice since these two SELECT statements differ only in where clause. This query is a simulation. My actual query is longer. My hope is to make this shorter query (without interior views).
with tmp as ( select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual UNION ALL select 'COMPLETE' status, 'GERMANY' country, 1 substatus FROM dual UNION ALL select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual) select v1.status, v1.country, v1.cnt01, v2.cntIncluding0 from (select status, country, count(*) cnt01 from tmp tmp1 group by status, country) v1 JOIN (select status, country, count(*) cntIncluding0 from tmp tmp2 where substatus=0 group by status, country) v2 on v1.status=v2.status and v1.country=v2.country;
totalnewby wrote:
Do I need to use these two interior views to display the results by group by a line? I can get the same result without having to type the same statement select twice since these two SELECT statements differ only in where clause. This query is a simulation. My actual query is longer. My hope is to make this shorter query (without interior views).with tmp as ( select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual UNION ALL select 'COMPLETE' status, 'GERMANY' country, 1 substatus FROM dual UNION ALL select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual) select v1.status, v1.country, v1.cnt01, v2.cntIncluding0 from (select status, country, count(*) cnt01 from tmp tmp1 group by status, country) v1 JOIN (select status, country, count(*) cntIncluding0 from tmp tmp2 where substatus=0 group by status, country) v2 on v1.status=v2.status and v1.country=v2.country;
SQL> with tmp as 2 ( 3 select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual UNION ALL 4 select 'COMPLETE' status, 'GERMANY' country, 1 substatus FROM dual UNION ALL 5 select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual 6 ) 7 select status, 8 country, 9 count(substatus) cnt01, 10 sum(decode(substatus, 0, 1, 0)) cntincluding0 11 from tmp 12 group by status, country 13 ; STATUS COUNTRY CNT01 CNTINCLUDING0 -------- ------- ---------- ------------- COMPLETE GERMANY 3 2
-
Small design on the points of view and a Where Clause Board...
Hi all... I just want to check Im doing things right, and he is not a better way to do this...
Running APEX 4.2.5 and XE 11.2
Ive built my application around a community of users who have access to certain groups of data... Ive designed so that there are views and then transparent filter the data of a given user. for example, the view below seamlessly that users can see the filters depending on which application they use, they can see more specifically, what are the features and finally, what group they are actually in.
Create view ENTITIES like)
Select * from t_entities t
where exists (select 1
of application_groups ag
where ag.object_name = 'ENTITIES '.
and ag.object_id = t.entity_id
and ag.group_name = 'CASH FLOW')
and exists (select 1 from entity_users EU
where eu.username = nvl (v ('APP_USER'), USER) / * APEX APPLICATION USER * /.
and eu.entity_id = t.entity_id)
and it exists (select 1 from entity_group_members for example
where eg.entity_group = v('G_ENTITY_GRP_ID') / * ENTITY_GROUP * /.
and eg.entity_id = t.entity_id)
)
The overall costs when I run the explain command is very low (23 or almost), so I think that its an effective way of filtering... However, out of 300 entities or greater, the vast majority of users (75%) can see 75% of data... Also, I need to create another view to filter another set of data with 2000 records. one with the view in place, 95% of the staff will see 95% of the data and only 10% of the staff see the other 10%...
I note that its faster when a member of a group brings back only a tiny part of the data compared to the other way around... This is why Im asking before implementing another view of the same type.
So, on my question. Is there a better way to do this, or the query should be on there head with a WHERE clause does NOT EXIST (xxxxx! = yyyyy)) or soemthing else ther is quite that Ive missed...
The only other comment is that Im using the upper table "APPLICATION_GROUPS" for more than one type of object (i.e. entities and entity accounts banking..) y at - it no merit in separaitng the two into two tables?
Thank you very much
Richard
Hi Richard,
Miss me a lot of information but:
I think that your design could be allowed. It seems a little too mat, maybe, but I think this could work.
It is important to have the good indexing and use compression of index:
On application_groups (object_name, the GroupName, groupname) compresses
IT compresses to entity_users (username, entity_id)
On the entity_group_members (entity_group, entity_id) compress
I think v as v ('G_ENTITY_GRP_ID') is a user-defined function? If so, if possible, set the deterministic and uses result_cache.
Consider partitioning application_groups type (= object_name?)
-
Dear all,
Kindly advise on below 2 doubts which have been daunting for quiet some time. The bottom has forced our requests to take alternative routes to receive solutions.
Doubt 1) is it possible for us to use 'select (*)' with a group and a join clause, if we have at least 2/3 tables with minimum 15-20 columns... given the constraint of having to add all the names column in the group by clause.
Question 2) is it possible to use "select" (*) with the exception of a single column of the table?
That is to say, I hate the output of a statement select (*) to have the entire field except a field in a tableAsk your advisor for the same thing. Excuse me because I have no examples to illustrate this point in time. A successful idea will do.
Thank you and best regards,
Séverine Suresh
Hey, Sebastian,
Séverine Suresh - 3035408 wrote:
Dear all,
Kindly advise on below 2 doubts which have been daunting for quiet some time. The bottom has forced our requests to take alternative routes to receive solutions.
Doubt 1) is it possible for us to use 'select (*)' with a group and a join clause, if we have at least 2/3 tables with minimum 15-20 columns... given the constraint of having to add all the names column in the group by clause.
Sure. If you had problems, you did it wrong. Your postal code, examples of data (CREATE TABLE and INSERT statements) and the results desired from these data.
Check out the Forum FAQ: Re: 2. How can I ask a question on the forums?
Normally, you don't want to ' SELECT *...» "in a join. Are most joins are equijoins, ' SELECT *...» "produced 2 copies of / columns used for Assembly. In addition, many tables have columns (for example, modified_date) that are not necessary in most applications.
All columns must be included explicitly in a GROUP BY clause. You cannot use * it.
You can not have parentheses around the * in ' SELECT *...» ». You might think 'SELECT COUNT (*) '
Question 2) is it possible to use "select" (*) with the exception of a single column of the table?
That is to say, I hate the output of a statement select (*) to have the entire field except a field in a table...
No.; If you don't want a particular column in the result set, you cannot use "SELECT *...» ».
Your front end can have so as not to display a column in the result set. For example, in SQL * more:
COLUMN modified_date NOPRINT
means that you won't see any column called modified_date.
-
May I ask where clause to satisfy two conditions at the same time (and)
Hello
I wrote a few joins and usually in the final stage where condition with certain conditions be satisfied in where clause. In all conditions where I only want one and condition fulfilled only if both are collected.
If we look at the this funciton is I should meet (get_order_type (ogr.order_number) <>'R')) AND wh1.third_party_warehouse! = 'Y') but I'm not get rid off both that if order_type is 'R' they are removed and if tooling_group is yes then ther are removed the result. I'm trying with both below pointed out together how can check these conditions? I can do in where clause?
((sg.tooling_stock_group <> 'Y'))
and
(get_order_type (ogr.order_number) <>'R'))
Of order_goods_received ogr
LEFT JOIN part_master pm
On ogr.part_number = pm.part_number
-stock_groups sg left join
SG stock_groups left join
on pm.stock_group = sg.stock_group
and ((sg.tooling_stock_group! = 'Y'))
and (get_order_type (ogr.order_number)! = 'R'))
-Pm.stock_group = sg.stock_group
LEFT JOIN batch_record_1 br1
-A FEW MORE CODE HERE-
WHERE ((ogr.delivery_date > = trunc (date_départ)))
AND
((ogr.delivery_date < = trunc (end_date)))
AND
OGR.goods_received_number <>'1' AND
get_order_type (OGR.order_number) NOT IN ('L') AND
OGR.returned_to_supplier_indicator not in('S','L') and
-sg.tooling_stock_group <>'Y '.
-((sg.tooling_stock_group <> 'Y') and (get_order_type (ogr.order_number) not in ('R')))
-(get_order_type (OGR.order_number) <>'R' AND sg.tooling_stock_group <>'Y')
((sg.tooling_stock_group <> 'Y'))
and
(get_order_type (ogr.order_number) <>'R'))
AND wh1.third_party_warehouse! = « Y »
UNION
(
Thank you.
Whenever you have a problem with such logic, you should try and draw a logic state diagram:
In your case, you are looking to two variables, with two possible States (equal to a value or is not it)
Then, take this sense of the sg.tooling_stock_group T and O as being the get_order_type (ogr.order_number) and create a state diagram logical based on your description of what you want. We will use a value of "Y" to indicate we want to record and a value of "N" to indicate the folder should not be returned.
Start with an empty logical diagram...
T = 'Y' T! = « Y »
+---------+---------+
| | |
| | |
| | | O = 'R '.
| | |
| | |
+---------+---------+
| | |
| | |
| | | O! = « R »
| | |
| | |
+---------+---------+First of all, you said: "If there is the result returned by the defined user function is"R"and the table that has the tooling_stock_group y then it should avoid this record."
T = 'Y' T! = « Y »
+---------+---------+
| | |
| | |
| N | | O = 'R '.
| | |
| | |
+---------+---------+
| | |
| | |
| | | O! = « R »
| | |
| | |
+---------+---------+Then you said: "If order_type does not return" R' but the tooling_stock_group is 'Y', then I should not avoid recording ".
T = 'Y' T! = « Y »
+---------+---------+
| | |
| | |
| N | | O = 'R '.
| | |
| | |
+---------+---------+
| | |
| | |
| Y | | O! = « R »
| | |
| | |
+---------+---------+Now, you have not given any logic for the rest of the diagram, so I made the assumption that you do not want to avoid these records...
T = 'Y' T! = « Y »
+---------+---------+
| | |
| | |
| N | Y | O = 'R '.
| | |
| | |
+---------+---------+
| | |
| | |
| Y | Y | O! = « R »
| | |
| | |
+---------+---------+Now there are different ways to determine the location of the clause of this diagram.
We could say that we want the records for all of the T column! = "Y" or all the records for all of the O line! " = R...where (sg.tooling_stock_group! = 'Y' or get_order_type (ogr.order_number)! = 'R')
We say we want to EXCLUDE (using DO NOT) all records where T = "Y" AND O = "O" "
If not (sg.tooling_stock_group = 'Y' and (ogr.order_number) get_order_type = 'R')
Those are the two most logical ways to do.
(In my previous answer, that we can see in this diagram, there is no need of the "or get_order_type (ogr.order_number).) (= 'R' "part, which is superfluous, but would not break it)Now let's look at your logic to see what it looks like to in the diagram...
where ((sg.tooling_stock_group <> «Y»))
and (get_order_type (ogr.order_number) <> 'R')
)In a logic diagram that looks to...
T = 'Y' T! = « Y »
+---------+---------+
| | |
| | |
| N | N | O = 'R '.
| | |
| | |
+---------+---------+
| | |
| | |
| N | Y | O! = « R »
| | |
| | |
+---------+---------+As you can see, your logic was only targeting one of the 4 possible results for select records and excluding 3.
-
Setting of outsourcing work is not for a SQL Where clause
Im trying to outsource the WHERE SQL clause of a snapshot data (connecting to Siebel DB) and specify where clause in the run profile that does not work.
Snapshot of research: Select the name of siebel.s_org_ext
Parameter of outsourcing: where_clause_sql
Run the content of the profile:
phase. Phase1.snapshot.clt.where_clause_sql = name = "ABC0009".
#phase. Phase1.snapshot.clt.snapshot_sql = select name from siebel.s_org_ext where name = 'ABC0009 '.
The above parameter retrieves all the records in the table. Below the profile execution retrieves just this record that seems to work fine.
Run the content of the profile:
phase. Phase1.snapshot.clt.snapshot_sql = select name from siebel.s_org_ext where name = 'ABC0009 '.
I want to outsource only where clause as there are many SQL and they are huge to maintain in the run profile.
I have attached a doco with screenshots that will help to understand more.
Hello
You must BE
-Choose "Select table or view" in the table of the snapshot Wizard selection page
&
-Use outsourced where clause
OR
-Choose "SQL" in the snapshot table selection wizard page.
&
-Outsourced use SQL snapshot
You can't mix and match options.
Kind regards
Nick
-
Dear friends,
Is there a way to access some of the columns using dblink but without using the quotes?
and also where clause without use of quote?
Please guide me
Thank you very much
Nithuser645399 wrote:
But is it possible to access Oracle's SQL Server using dblink without quotes to select columns?YES, it is possible, but the table names and column names must be UPPERCASE only
-
Outer joins and null in the 'where' clause condition
Hi people,
Please help me on this.
Here's my query.
with x
(select 'a' as a dual union all col1)
Select 'b' as col1 of union double all the
Select 'c' as double col1
),
y as
(
Select 'b' as col2 from dual Union all the
Select 'c' as col2 from dual Union all the
Select would be "as col2 from dual Union all the"
Select 'e' as col2 from dual
)
Select * x y right outer join
on x.col1 = y.col2 and y.col2 is null
Get all the lines of 'COL1' as null. Why like this?
Just add the condition to the WHERE clause for example
WITH x AS (SELECT 'a' AS col1 FROM dual UNION ALL SELECT 'b' AS col1 FROM dual UNION ALL SELECT 'c' AS col1 FROM dual ), y AS ( SELECT 'b' AS col2 FROM dual UNION ALL SELECT 'c' AS col2 FROM dual UNION ALL SELECT 'd' AS col2 FROM dual UNION ALL SELECT 'e' AS col2 FROM dual ) SELECT * FROM x LEFT OUTER JOIN y ON x.col1=y.col2 ----want to add "and y.col2 is null " condition to get value "a" where y.col2 is null
-
Update statement with joins of tables and where Clause
Hi, I have MS SQL background and I try to execute an update statement in Oracle with joins of tables. However, the syntax below does not work but I think it works for MS SQL.
Basically, the base table must be attached to a master table trend with monthly snapshots, an account will be only an entry for a given date monthly. Where clause must be limited to accounts within a certain range of interest rates.
The first approach returns command SQL ORA-00933 not correctly completed, and the second approach returns ORA-01427 row below query returns multiple rows. Can anyone help? Thanks in advance!
1:
Update PenaltyAll
Set a.indicator = month (b.)
of PenaltyAll an inner join Master b on a.acctno = b.accountnumber
where a.monthend='01/31/2009' and b.date='12/31/2008' and b.apr < 20
2:
Update PenaltyAll
adjustment indicator =
(select to_char (b., 'MM')
of PenaltyAll an inner join Master b on a.acctno = b.accountnumber
"where to_char (a.monthend,'mm/dd/yyyy ') = 31 January 2009"
(et to_char(b.date,'mm/dd/yyyy') = December 31, 2008 "
and b.apr < 20)
Published by: sqlrookie on August 21, 2009 07:04I edited my post, that was my mistake, ANC you try now?
-
Complex Inner Join and outer subquery where clause to join internal?
The DDL for this post was too big and I had to put on my site:
http://www.harbortownsolutions.com/DDLForDORTable.txt
My goal is to create a report of sales data for 116 stores containing daily sales and count of comments in recent years. My challenge is that I am pulling data from the same table, but with different dates to get data from last year and the week in data from date of last year.
The dates used for reports are:
SalesDate = 06/04/2009
SalesDateForLastYear = 2008-06-05
SalesDateBeginningOfWeek = 01/06/2009
SalesDateBginningOFWeekLastYear = 2008-06-02
PSEUDOQUERYS:
Question: Since they all use the same store of nbrs, I specify on each request? Can't I just specify only once on outer query Where clause?---======= DOLLAR VARIANCE = You Said you have $100 worth of meat(inventory) but you only have $50 worth of meat SELECT BUSI_DATE as BusinessDate, ORACLE_KEY as StoreID, FIELD1 as Sales, FIELD2 as GuestCount, FIELD3 as DollarVariance, FIELD4 as Cars FROM MYDAILYTOTALS WHERE Busi_date = SalesDate AND ORACLE_KEY IN (SELECT StoreID From MyStores); -======= ONLY Guest count and Sales are needed in comparisons against last year ---====== Last YEar dates = corresponding dates for this year ie Tuesday of this week matched to Tuesday of last year (except for leap year) SELECT ORACLE_KEY as StoreID FIELD1 as SalesLastYear FIELD2 as GuestCountLastYear FROM MYDAILYTOTALS WHERE Busi_date = SalesDateForLastYear AND ORACLE_KEY IN (SELECT StoreID From MyStores); SELECT ORACLE_KEY as StoreID SUM(FIELD1) as WeekToDateSales SUM(FIELD2) as WeekToDateGuestCount FROM MYDAILYTOTALS WHERE Busi_date BETWEEN SalesDateBeginningOfWeek and SalesDate AND ORACLE_KEY IN (SELECT StoreID From MyStores) GROUP BY ORACLE_KEY --======= SELECT ORACLE_KEY as StoreID SUM(FIELD1) as WeekToDateSalesLastYear SUM(FIELD2) as WeekToDateGuestCountLastYear FROM MYDAILYTOTALS WHERE Busi_date BETWEEN SalesDateBeginningOfWeekLastYear and SalesDateLastYear AND ORACLE_KEY IN (SELECT StoreID From MyStores) GROUP BY ORACLE_KEY
Also, how would fit the following of HOEK script:
See how I put 1 field based on another field value
He reads a record for each store of 116 stores in the database. There are 2 situations that have been addressed by Hoeks code:
For each of the 116 stores in the store table, there must be 1 and only
registration of 1 stock to match the record of MyStoreTotals. However, sometimes there is no record of inventory.
and sometimes there will be 2 (in a case where a manager of database updates)
After daily treatment) files. If so, the record with Is_posted = 1
is the one that should be included in the query. The following text accomplishes this:
-chr (39) is the single quote
Can I put this request on the place where clause of the outer to query I put on a JOIN clause?Select StoreId, DollarVariance from (select store.storeid, case when inv.storeid is null then 'None' when inv.is_posted = 0 then 'NP' else chr(39)||inv.total_dol_var||chr(39) end as DollarVariance, row_number() over (partition by store.storeid order by inv.is_posted desc) rn from myInven inv right outer join mystores store on store.storeid = inv.fk_str_main_id and inv.busi_date = to_date(SalesDate, 'dd-mon-yyyy')) where rn = 1;
So I guess that's why you used the MAX.
That is right.
I used CASES to identify and complete the necessary columns since the first set of results (WITH).
So then I more or less "swivels somehow" lines of this result set to the columns, each store will appear once the most. -
Try adding conditions to clause "and" stored in the table for the where clause, unknown syntax
I am trying to add additional segments to the 'where' clause, and I don't know exactly how to proceed. I am currently using another table to search for keywords and sometimes there aren't everything. I use this table containing the key words to search the description and associate a symbol with a path.
The code loops through the keywords with the keywords most associated and try to find links to a symbol then excludes those and search for symbols that correspond to those with less keywords and all. I am able to do this with 6 queries and manually changing the arguments, but I want to loop together so that if the changes need to be made in the future, I won't need to go digging in the code.
Thanks, but that's ok. I already have a solution for this.
-
Difference in WHERE clause VO and java class!
Hello!
I have VO:
When I put the value of VO in java classSELECT ADokumenti.A_DOKUMENTI_PK, ADokumenti.APRAKSTS, ADokumenti.DOKUMENTA_TIPS, ADokumenti.DOKUMENTS, ADokumenti.FAILA_VARDS, ADokumenti.PASES_DATI_ID, ADokumenti.PIEVIENOSANAS_DATUMS FROM A_DOKUMENTI ADokumenti WHERE ADokumenti.DOKUMENTA_TIPS = 'image/jpeg' or ADokumenti.DOKUMENTA_TIPS = 'image/gif' or ADokumenti.DOKUMENTA_TIPS = 'image/png'
WHAT result would be? Only java put where clause, or both?vo.setWhereClause("A_DOKUMENTI_PK="+imageId);
If one clause of java, and then how to add this: «A_DOKUMENTI_PK = "+ imageId vo?»
Best regards, Debuger!Debuger,
That's why I suggested that you create a view named criteria (with a variable binding) at design time. At runtime, you set the value of the variable binding and apply the criteria to view. The first link in the documentation I gave explains you quite well.
You must use bind variables for five reasons:
(1) performance
(2) performance
(3) performance
(4) performance
and
(5) performance.Oh and
(6) avoid errors of insufficient memory in the shared the database pool.
John
-
Cannot run a «BUSINESS...» WHEN ' with a date in a WHERE CLAUSE condition
Hello
I need to check for a condition and date according to the date, he would check a set of host names or the other game... so I thought I could write something like this in the WHERE clause:
AND HOST_NAME IN (
CASE
WHEN TO_DATE (: StopDate, 'MON-DD-YYYY') > = TO_DATE ('22 - DEC - 2015 "," DD-MON-YYYY ') THEN
('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC') ON THE OTHER
("SERVERNAME1", "NAMESERVER2", "SERVERNAME3")
END
)
I get the following:
ORA-00907: lack of right parenthesis
00907 00000 - "lack the right parenthesis.
But there is no missing parentheses!
If I take the case... when... end, and run the host_name in ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC') (separately, they run fine)...
I also tried:
AND
( CASE
WHEN TO_DATE (: StopDate, 'MON-DD-YYYY') > = TO_DATE ('22 - DEC - 2015 "," DD-MON-YYYY ') THEN
HOST_NAME IN ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC') ELSE
HOST_NAME IN ('SERVERNAME1","NAMESERVER2","SERVERNAME3")
END
)
the error I get is:
ORA-00905: lack of keyword
00905 00000 - 'lack the key word'
What keyword miss me?
Post edited by: c75d2e42-06a0-4eb1-a576-5652edcbfbe8
Hello
c75d2e42-06a0-4eb1-A576-5652edcbfbe8 wrote:
It was a typo when transferred to the Oracle forum... the version of Oracle is: PL/SQL version 10.2.0.3.0 (10 G)
I also used IF the statement and that has not worked (in error "missing parenthesis") which I'm sure is a matter of "syntax"... I did not know that the CASE statement returns the value single only, so it's probably the problem. Is it possible to re - write this?
...
IF only works in PL/SQL. It does not in SQL, even if that SQL is embedded in PL/SQL.
There are many ways to re - write the condition. And here's one:
AND ((host_name IN ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC')
AND TO_DATE (: StopDate, "MON-DD-YYYY") > = TO_DATE ('22-DEC-2015', "MON-DD-YYYY")
)
OR (host_name IN ('servername1","Nameserver2","SERVERNAME3")
AND TO_DATE (: StopDate, "MON-DD-YYYY")< to_date="" ('dec-22-2015', =""> >
)
)
If: StopDate can be NULL, it must be a bit more complicated.
You can also use nested, such as CASE expressions
AND THE CASE
WHEN TO_DATE (: StopDate, "MON-DD-YYYY") > = TO_DATE ('22-DEC-2015', "MON-DD-YYYY")
WHILE CASE
WHEN host_name IN ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC')
AND THEN 'OK '.
END
OTHER CASES
WHEN host_name IN ('servername1","Nameserver2","SERVERNAME3")
AND THEN 'OK '.
END
END = 'OK '.
I wonder if this in your application is the best way, however. If SERVERNAMEA was put into service on December 22, maybe that that fact should be recorded in a table. If you have a table with 1 row per server, you can consider adding 2 columns DATE to show when the server was first and last used. Then, rather than use a WHERE clause to test servers appropriate, you could do an inner join.
Maybe you are looking for
-
When I click on a link (almost everywhere) a tab or a window opens with an investigation, usually with a voice and music. When I close the Firefox with all the close tabs.
-
I can't close or delete the file, the button disappeared
Since I updated to Firefox, at the top of the page where it says FILE, EDIT, VIEW, HISTORY, etc. under the button FILE, the close button is gone & in order to close or delete a file, I have to LEAVE my computer. His TERRIBLE...
-
Re: Pink and green screen on the Satellite X 200
A difficult for all a... my laptop screen is a nice pink and green but if I connect to my TV via HDMI, it works perfectlyThank youTrevor
-
Satellite Pro L850-1DZ - wireless keeps dropping
Hi all. Thank you for taking the time to read this. I have a Satellite Pro L850 1DZ and my wifi guard fall then plugging himself. It does this to Uni, in my old House and the new. The router was changed when I moved. It can fall so im sitting next to
-
Need to install Win7 order for Portege Z30
Hello I intend to "down-grade" my new Z30 to Windows 7 Pro 32 Bit. This is how I can run some specific software. I have all the 32-bit drivers downloaded and ready. Can someone give me an idea about the order of installation good (or better)? Thank y