Stmts SELECT with a Having Clause
HelloA body can help me to improve the performance of the query below...
Select t.seq_no, t.contract_id, t.date_from in test_plan_tab t
Group of t.seq_no, t.contract_id, t.date_from
seen (select count (*)
of test_plan_tab p
where p.contract_id = t.contract_id
and p.date_from = t.date_from) > 1
The clause will reduce the performance of the query above, I guess as seen...
Thank you and best regards,
/ Dieng...
In order to analyze the table only once you can try something like this:
SELECT seq_no, contract_id, date_from
FROM (SELECT t.seq_no, t.contract_id, t.date_from, COUNT(*) over(PARTITION BY contract_id, date_from) count_filter
FROM test_plan_tab t
GROUP BY t.seq_no, t.contract_id, t.date_from)
WHERE count_filter > 1
Published by: fsitja on March 18, 2010 02:08
Tags: Database
Similar Questions
-
Hi all
I have this select statement to help to filter different from zero records.
Select GroupName, Nom_liste,
Sum ((a_cost/1000) * degradation * quantity * total_count * index) such as total_cost,.
FROM MyTable
having sum ((a_cost/1000) * degradation * quantity * total_count * index) <>0
Group GroupName, Nom_liste
Having done so the query to run more slowly.
How can I filter records with zero total_cost (they can be negative or greater than zero).
Thank you!
Hello
user9542267 wrote:
Hi all
I have this select statement to help to filter different from zero records.
Select GroupName, Nom_liste,
Sum ((a_cost/1000) * degradation * quantity * total_count * index) such as total_cost,.
FROM MyTable
having sum ((a_cost/1000) * degradation * quantity * total_count * index) <> 0
Group GroupName, Nom_liste
Having done so the query to run more slowly.
How can I filter records with zero total_cost (they can be negative or greater than zero).
Thank you!
The query you posted should not take more time with or without the HAVING clause. The right of the comma before 'from' causes a compilation error very quickly anyway.
If you get no result other than an error message, then this is not the code you are running. Show the code you actually run, or a simplified version that has the same problem.
For all performance issues, see the FAQ forum:
https://community.Oracle.com/message/9362003#9362003
If the problem was really in the HAVING clause, then you can try something like this:
WITH got_total_cost AS
(
SELECT GroupName, Nom_liste
, SUM ((a_cost/1000) * degradation * quantity * total_count * index) SUCH as total_cost
FROM MyTable
GROUP BY GroupName, Nom_liste
)
SELECT *.
OF got_total_cost
WHERE as total_cost <> 0
;but it would be very surprising he made all the difference. I suspect that the problem is not really in the HAVING clause.
-
try to get the SUM of all of the charges with the having clause
Hi Oracle users.
I'm trying to accomplish to get a sum of a series of charges and it should be easy, but I can't get it.
For example, I have the following.
Select ACCTLOC, count(ACCTLOC) AS TOTALP FROM BOX_ACCTS_TBL WHERE TIME_REQ > SYSDATE-120 Group By ACCTLOC having (count(ACCTLOC) > 1) the results are ACCTLOC TOTALP Philly 15970 NY 8623 Tacoma 3 SanFran 195 Hartford 5 Miami 4374
How can I get the SUM of this group? Do I put this in PL SQL and do a procedure to carry out the selection? Is this the way to go on this?
I appreciate all the comments you can give.Thank you!
with
query_result as
(select 'Philly' acctloc, 15970 totalp Union double all the)
Select "NY", 8623 Union double all the
Select "Tacoma", 3 double Union all
Select "SanFran", 195 double Union all
Select "Hartford", 5 Union double all the
Select 'Miami', double 4374
)
Select acctloc, totalp, sum (totalp) on the_sum, avg (totalp) (on the_avg), ratio_to_report (totalp) (percentages))
of query_result
ACCTLOC TOTALP THE_SUM THE_AVG PERCENTAGES Philly 15970 29170 4861.66666666666666666666666666666666667 .547480287967089475488515598217346588961 NY 8623 29170 4861.66666666666666666666666666666666667 .295611930065135413095646211861501542681 Tacoma 3 29170 4861.66666666666666666666666666666666667 .000102845389098388755570791909496057593 SanFran 195 29170 4861.66666666666666666666666666666666667 .006684950291395269112101474117243743572 Hartford 5 29170 4861.66666666666666666666666666666666667 .000171408981830647925951319849160095989 Miami 4374 29170 4861.66666666666666666666666666666666667 .149948577305450805622214604045251971203 Concerning
Etbin
-
Cannot wrap a select with order by clause in a file.
TOGETHER SET TERMOUT OFF FEEDBACK OFF PAGESIZE 0 400 LINESIZE ECHO OFF OFF POSITION
coil & 1;
Select "EMPID, EMP_NAME, REGION, FROM, TO, MONTH, ACTIVITY_TYPE, PROJECT_PIN, MILESTONE_NAME, PRACTICE_ID, RESOURCE_CATEGORY, HOURS, COMMENT, percent ALLOCATION, INVOICE_TO, the STATE of the double"
Union of all the
select empid,resource_name,region,week_of,(week_of+7),core_month,bill_rate,project_name,project_type,milestone_name,practice_id,resource_category,total_hours_submitted,project_type,"%ALLOCATION",invoice_to,status from master_emp_allocation order by week_of;
spool off;
"exit";
/
the above block gives result below
select empid,resource_name,region,week_of,(week_of+7),core_month,bill_rate,project_name,project_type,milestone_name,practice_id,resource_category,total_hours_submitted,project_type,"%ALLOCATION",invoice_to,status from master_emp_allocation order by week_of
*
ERROR at line 3:
ORA-00904: "WEEK_OF": invalid identifier
---------------------------------------------------------------------------
Without the order by clause it wraps the file passed as an argument.
check
Combining the UNION AGENDA and BY
Columns in the ORDER BY list must be a subset of the columns in the selection list on the left side of the union.
All the columns in the ORDER BY list should be sorted in ascending order, and they must be a prefix in the order of the columns in the target of the left side of the UNION list.
-
I have trouble understanding the following query:
SELECT cust_city, COUNT (cust_last_name)
Customers
WHERE cust_credit_limit > 1000
GROUP BY cust_city
HAVING AVG (cust_credit_limit) BETWEEN 5000 AND 6000
According to my preparation for the review, it will work successfully without errors, although I don't understand why.
The AVG (cust_credit_limit) should also be included in with the rest of the fields to make it work correctly?
It would be greatly appreciated if someone could explain it to me better.
Thank you
Sean
5285cd35-2ff3-432e-B2FD-19285481be60 wrote:
I have trouble understanding the following query:
SELECT cust_city, COUNT (cust_last_name)
Customers
WHERE cust_credit_limit > 1000
GROUP BY cust_city
HAVING AVG (cust_credit_limit) BETWEEN 5000 AND 6000
According to my preparation for the review, it will work successfully without errors, although I don't understand why.
The AVG (cust_credit_limit) should also be included in with the rest of the fields to make it work correctly?
It would be greatly appreciated if someone could explain it to me better.
Thank you
Sean
No - the AVG function doesn't have to be in the select list. Explain why you think it should be.
How would it make a difference if you added to the SELECTION list and ignored, then?
When you have questions DOC the first thing you need to do is RTFM. See the HAVING clause in the RFSO of the SQL language
http://docs.Oracle.com/CD/B28359_01/server.111/b28286/statements_10002.htm
>
HAVING clause
Use of the
HAVING
clause to restrict groups of returns of the lines to these groups for which the specifiedcondition
isTRUE
.>
As the doc t says
He HAVING condition applies to the 'groups '.
If you use the HR. EMPLOYEES table you can see the effect of the HAVING clause. This query is similar to yours but with none HAVING clause, and the AVG (salary) added to the selection list to see which groups will have
>
Select department_id, count (last_name), avg (salary)
employees
where salary > 500
Group by department_id- DEPARTMENT_ID, COUNT (LAST_NAME), AVG (SALARY)
- 10,1,4400
- 20,2,9500
- 30,6,4150
- 40,1,6500
- 50,45,3475.55555555556
- 60,5,5760
- 70,1,10000
- 80,34,8955.88235294118
- 90,3,19333.3333333333
- 100,6,8601.33333333333
- 110,2,10154
- 1,7000
>
Note that 60 is the ONLY group with AVG (salary) between 5000 and 6000
Now, try the query using the HAVING clause
>
Select department_id, count (last_name)
employees
where salary > 500
Group by department_id
having avg (salary) between 5000 and 6000
DEPARTMENT_ID, COUNT (LAST_NAME)
60.5
>
Only group 60 has been selected - the HAVING condition has been applied to the first query GROUPS, not the lines.
-
Adding a HAVING clause in the BI tools
Hello
I have to build a BI reporting tool that counts students participating in academic programs.
I am limited to display data personal due to the regulation of the right, so I do the classes on a higher leverage. (Example: the size of the location has records of the regions instead of the city).
But the sill, I can't guarantee that the report will not show only one or two records for a combination of dimension values.
Software Oracle BI (as Oracle BI) has the functionality to add a HAVING clause in my selection as the final select statement sent to the database of the data store will be:
Select d.region_name
count (*)
location d
f participation
where f.location_id = d.location_id
D.region_name group
Having count (*) > 5
With such a feature, I could drop the possibility of exploiting personal data.
ARO
Ales
If you wanted to make a report, do you mean to use an Oracle BI answers, really?
First of all, in Oracle BI answers, you could change your filter:
And use something like this:
All,
Kind regards
-
Use of the place where and having clause
Hi all
I have always a doubt as to the use of HAVING and WHERE clause.
Suppose I have table T1 with a single column C1
CREATE TABLE T1
(C1 VARCHAR2 (1));
who data following INSERT scripts
INSERT INTO T1 VALUES ('A');
INSERT INTO T1 VALUES ('B');
INSERT INTO T1 VALUES('C');
INSERT INTO T1 VALUES ('A');
INSERT INTO T1 VALUES ('B');
INSERT INTO T1 VALUES ('A');
Now I want the result as follows
C1 = COUNT (C1)
==============
B = 2
A = 3
Then out of query 1 and 2, approach who is right?
(1) SELECT C1, COUNT (C1) FROM T1
WHERE C1 <>'C '.
GROUP BY C1
ORDER BY C1 DESC;
(2) SELECT C1, COUNT (C1) FROM T1
GROUP BY C1
SEEN C1 <>'C '.
ORDER BY C1 DESC;
Published by: user13306874 on June 21, 2010 02:36In SQL, it is always better to filter data as soon as possible of the moment.
In your example, the WHERE clause would be right now:SQL> explain plan for 2 select c1,count(c1) 3 from t1 4 where c1 != 'C' 5 group by c1 6* order by c1 desc; Explained. SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT ---------------------------------------------------- Plan hash value: 3946799371 ---------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ---------------------------------------------------- | 0 | SELECT STATEMENT | | 5 | 10 | | 1 | SORT GROUP BY | | 5 | 10 | |* 2 | TABLE ACCESS FULL| T1 | 5 | 10 | ---------------------------------------------------- Predicate Information (identified by operation id): 2 - filter("C1"!='C') 18 rows selected. SQL>
As you can see that the filter is applied during the analysis of T1.
Whereas in the case of HAVING:
SQL> explain plan for 2 select c1,count(c1) 3 from t1 4 group by c1 5 having c1 != 'C' 6* order by c1 desc; Explained. SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT ---------------------------------------------------- Plan hash value: 3146800528 ---------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ---------------------------------------------------- | 0 | SELECT STATEMENT | | 6 | 12 | |* 1 | FILTER | | | | | 2 | SORT GROUP BY | | 6 | 12 | | 3 | TABLE ACCESS FULL| T1 | 6 | 12 | ---------------------------------------------------- Predicate Information (identified by operation id): 1 - filter("C1"!='C') 18 rows selected. SQL>
The analysis is performed after all groups have been calculated: which was calculated in vain, because it will be further filtered because of the HAVING clause.
In general, I would like to use as a guide: If you do not use aggregate functions in your predicate in the HAVING clause, set this predicate to the WHERE of your query part.
Published by: Toon Koppelaars June 21, 2010 11:54
-
ORDER BY clause or HAVING clause... ERROR
Hi, I request what error throws please find the solution for the application to go without danger...
Select C.src_cd,
D.src_nm,
Count (*) supp_clm_count,
(CASE WHEN A.clm_ttladjamt > 0 then A.clm_ttladjamt to another A.clm_ttlreqamt END) as the amount
Of IWOWNER. WC_clm, a.
IWOWNER. WC_clm_srvc B,.
LOVELY. WC_SRC C.
LOVELY. WC_SRC_lang D
where A.clm_id = B.clm_id
and A.rcv_loc_id = C.src_id
and C.src_id = D.src_id
and TRANSLATE (A.clm_rqst_type_cd) = "SUPPLIERCLAIM".
and TRANSLATE (A.clm_typ_cd) in ('GUARANTEE', 'PRE-DELIVERY')
and DATE (A.clm_create_dt) between January 1, 2000 "and on January 1, 2010"
C.src_cd group, D.src_nm
ERROR:
-------
SQLSTATE: 42803, SQLERRMC: CLM_TTLADJAMT
Message: An expression starting with "CLM_TTLADJAMT" specified in a SELECT clause, HAVING clause, or ORDER BY clause is not specified in the GROUP BY clause or a SELECT clause, a HAVING clause ORDER BY clause with a column function and no GROUP BY clause is specifiedHello
With oracle, you can try this query.
Salim cordially.
/* Formatted on 2009/07/22 10:10 (Formatter Plus v4.8.8) */ SELECT DISTINCT c.src_cd, d.src_nm, COUNT (1) OVER (PARTITION BY c.src_cd, d.src_nm) supp_clm_count, (CASE WHEN a.clm_ttladjamt > 0 THEN a.clm_ttladjamt ELSE a.clm_ttlreqamt END ) AS amount FROM iwowner.wc_clm a, iwowner.wc_clm_srvc b, showner.wc_src c, showner.wc_src_lang d WHERE a.clm_id = b.clm_id AND a.rcv_loc_id = c.src_id AND c.src_id = d.src_id AND a.clm_rqst_type_cd = 'SUPPLIERCLAIM' AND a.clm_typ_cd IN ('WARRANTY', 'PRE-DELIVERY') AND a.clm_create_dt BETWEEN TO_DATE ('01/01/2000', 'dd/mm/yyyy') AND TO_DATE ('01/01/2010', 'dd/mm/yyyy')
-
Apparently, my memory is almost full - no idea how to deal with not having a novice such am - sd card
Hi sixty.
It can also be a good idea to begin to transfer the content from your phone to a PC/Mac to help reduce the storage room.
It is a process usually easy, just plug the unit to a PC, on the phone screen select MTP mode when it appears.
Once finished, you just have to access the phone's internal memory and transfer pictures/videos from the DCIM folder.
Let us know if you need help in this kind of task.
-
Need help with dynamic where clause.
Hello world. I'm kind of a novice with PL/SQL, so please be patient with me. I am building a web application using Weblogic Oracle 11 g and Oracle database.
To make a long story short, I need to generate the complex dynamic WHERE clause. I don't know what will be the name of the column or the operator of comparison or the value will be until the moment of execution.
I'm not 100% certain, but I think I need to use dynamic SQL statements. Unless there is a better way to do it.
I'm sure that using dynamic SQL opens me up to SQL injection attacks if I use simple string concatenation. I would like to use bind variable if possible.
In any case, it seems like trying to build a dynamic where clause does not seem to work as I want it would be...
bv1 := 'colA = 5 and colB >= 9'; query_str := 'SELECT * FROM view WHERE :bv1'; OPEN CUR FOR query_str USING bv1;
The code above pours out when I try to run it.
Is there a way to build dynamic where the provisions without the use of concatenation of simple string that leaves me open to attacks by SQL injection?
Thank you
Hello. I have read briefly upward on things, you suggested, but it seems a bit abstract for me since I was a novice.
Can you give us an explanation or an example of how to use it to accomplish what I need to do?
Do ypu really plan create a query with a WHERE clause that contains a predicate for all possible columns?
Variable bind offer performance when the same query is executed several times with different values for bind variables.
Select * from emp where empno =: v_empno
After the first run Oracle will always be this query in the library cache. The next running can use the version of the cache even if the bind value is different.
Select * from emp where empno =: v_empno;
Select * from emp where ename =: v_ename;
Select * from emp where sal =: v_sal;
Each one is a DIFFERENT query. Yes - each of them uses a variable binding, but queries are different.
So, if your username select EMPNO, an '=', and a value from the first query can be executed. But the next time that the user can select the ENAME column so that 'stored' first request may not be used given that the query does not match.
The third time your user selects SAL so none of the first two queries can be used in the library cache. The use of bind variables gives performance during the SAME QUERY is used multiple times with DIFFERENT values for the variable binding. Oracle is not to analyze the hard query everything simply because the VALUE is different.
So bind variables do not help you if most of the queries were completely DIFFERENT sets of predicates. And SYS_CONTEXT will not help either since that simply provides a way to define binds the values of the variables.
Just for the simple example above, there are at least SIX possible combinations of columns that could choose your user name: empno, ename, sal, empno ename, empno & sal, ename & sal
-
Cannot set keyframes in the audio clip selected with the pen tool - cannot see even the line volume control more to set keyframes on having developed the clip. What could be the problem? I use the first CC pro @.
You can use the Ctrl key and then click with the regular selection tool, clicking with ctrl will make a new keyframe. in this way, have no need for the tools. CTRL has other great shortcuts that will stop you having to spend retouching pads tools too.
If the automation keyframe line is missing, you can switch on and off in the menu sequence.
-
Hai all,
I have problem with order by clause,
My query is
"Select number from table1 order number CSA.
and the output as
1
10
12
13
15
17
19
2
20
21
22
.
........
But if we give the order that it should display below the only good?
1
2
10
12
13
15
17
19
20
21
22 ........
Help me please why it is not displayed as she. and how to make the statement to display as in the second case. Thanks in advance.
Kind regards
UrajaIn your table, the column is VARCHAR2 data type.
It is a string, even if it is to store numeric values, it will get condemn as strings
Try the below
select your_column from table1 order by to_number(your_column) asc
Published by: JAC on November 19, 2012 16:35
-
How to create a procedure for REF CURSOR output with any WHERE clause?
I have a requirement like this: I have a huge question that need to reuse in my code over 10 times. This SQL has about 50 lines. Here for these 10 odd times sometimes changes in WHERE clause (columns are the same). So I can't create a view as SQL is not static.
I thought to write a procedure with a para of WHERE_CLAUSE entry. I pulled out a refcursor sys by adding where clause. But I can't do it because you cannot add a clause like this where clause.
i.e.
The foregoing gives an error.PROCEDURE dynamyic_query (p_where_clause IN VARCHAR2, p_out_query OUT SYS_REFCURSOR ) IS BEGIN OPEN p_out_query FOR SELECT ......... FROM table WHERE || ' ' || p_where_clause; END;
How to handle such a situation? Any help would be greatly appreciated.Hello
Channa wrote:
... However, when I change the procedure like this:PROCEDURE FORMS_TEXT_DYN_SQL_TEST(p_where_cluase IN VARCHAR2, p_out_cursor OUT SYS_REFCURSOR) IS v_stmt VARCHAR2(1000); BEGIN v_stmt := 'SELECT tname FROM tab_test WHERE tname LIKE ''%ABS_V4%'' AND :y'; OPEN p_out_cursor FOR v_stmt using p_where_cluase; END;
And run this block of code:
declare v_tname varchar2(200); out_cursor sys_refcursor; begin forms_text_dyn_sql_test(' 1 = 1 ', out_cursor ); LOOP fetch out_cursor INTO v_tname; exit when out_cursor%NOTFOUND; DBMS_OUTPUT.PUT_LINE(v_tname); END LOOP; end; /
I get the error:
[1]: (Error): ORA-00920: invalid relational operator ORA-06512: at "ABS.FORMS_TEXT_DYN_SQL_TEST", line 6 ORA-06512: at line 5
Looks like you can only set column_name =: z, column_name =: values of type y. You can not it seems to replace it with no WHERE CLAUSE?
A bind variable, such as: it, represents a single value.
If: is the VARCHAR2 '1 = 1', thenSELECT tname FROM tab_test WHERE tname LIKE '%ABS_V4%' AND :y
takes the value
SELECT tname FROM tab_test WHERE tname LIKE '%ABS_V4%' AND '1 = 1'
I think you want something like this:
CREATE OR REPLACE PROCEDURE FORMS_TEXT_DYN_SQL_TEST ( p_where_clause IN VARCHAR2 , p_out_cursor OUT SYS_REFCURSOR ) IS v_stmt VARCHAR2(1000); BEGIN v_stmt := 'SELECT ename FROM scott.emp WHERE ename LIKE ''%A%'' AND ' || p_where_clause; OPEN p_out_cursor FOR v_stmt; END; / show errors SET SERVEROUTPUT ON declare v_tname varchar2(200); out_cursor sys_refcursor; begin forms_text_dyn_sql_test(' 1 = 1 ', out_cursor ); LOOP fetch out_cursor INTO v_tname; exit when out_cursor%NOTFOUND; DBMS_OUTPUT.PUT_LINE(v_tname); END LOOP; end; /
Output:
ALLEN WARD MARTIN BLAKE CLARK ADAMS JAMES
-
outer join on query with the GOLD clause
Hi all, I have a problem outerjoining a clause or a request with
Here's my data
as you can see I am attaching the table 1 and table 2. I join with txt1, if txt1 is null, then join by txt2, if null, then reach by txt3 and so on.WITH table1 AS ( SELECT 'test' txt1, 'pak' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL SELECT null txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL SELECT null txt1, NULL txt2, 'ced3' txt3, 'su3' txt4 FROM dual UNION ALL SELECT null txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL SELECT 'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL SELECT null txt1, NULL txt2, null txt3, null txt4 FROM dual ) ,table2 AS ( SELECT 111 pid, 'test' txt1, 'pak4' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL SELECT 222 pid, 'test1' txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL SELECT 333 pid, 'test2' txt1, 'pak3' txt2, 'ced3' txt3, 'su4' txt4 FROM dual UNION ALL SELECT 444 pid, 'test2' txt1, 'pak3' txt2, 'ced4' txt3, 'su3' txt4 FROM dual ) SELECT b.pid, a.* from table1 a, table2 b WHERE (a.txt1 = b.txt1 OR a.txt1 IS NULL AND a.txt2=b.txt2 OR Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 = b.txt3 OR Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 IS NULL AND a.txt4 = b.txt4 )
the above produces this output code
This output is partially correct. only 4 lines were in display and two has been left outPID TXT1 TXT2 TXT3 TXT4 === ==== === ==== ==== 111 test pak ced su 222 pak ced2 su2 333 ced3 su3 444 su3
I tried to use the outer join, but oracle will complain that I can't use outerjoin with the GOLD clause.SELECT 'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL SELECT null txt1, NULL txt2, null txt3, null txt4 FROM dual
can someone modify my query to display the output below?
PID TXT1 TXT2 TXT3 TXT4 === ==== === ==== ==== 111 test pak ced su 222 pak ced2 su2 333 ced3 su3 444 su3 NULL NULL NULL NULL NULL test5
Not sure you can do it with the style of the Oracle of outer joins, but open ANSI style joins is simple, in fact exactly as you had it.
SQL> set null null; SQL> WITH table1 AS ( 2 SELECT 'test' txt1, 'pak' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL 3 SELECT null txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL 4 SELECT null txt1, NULL txt2, 'ced3' txt3, 'su3' txt4 FROM dual UNION ALL 5 SELECT null txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL 6 SELECT 'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL 7 SELECT null txt1, NULL txt2, null txt3, null txt4 FROM dual), 8 table2 AS ( 9 SELECT 111 pid, 'test' txt1, 'pak4' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL 10 SELECT 222 pid, 'test1' txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL 11 SELECT 333 pid, 'test2' txt1, 'pak3' txt2, 'ced3' txt3, 'su4' txt4 FROM dual UNION ALL 12 SELECT 444 pid, 'test2' txt1, 'pak3' txt2, 'ced4' txt3, 'su3' txt4 FROM dual) 13 SELECT b.pid, a.* 14 from table1 a 15 LEFT JOIN table2 b 16 ON (a.txt1 = b.txt1 OR 17 a.txt1 IS NULL AND a.txt2=b.txt2 OR 18 Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 = b.txt3 OR 19 Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 IS NULL AND a.txt4 = b.txt4); PID TXT1 TXT2 TXT3 TXT4 ---------- ------ ------ ------ ------ 111 test pak ced su 222 null pak ced2 su2 333 null null ced3 su3 444 null null null su3 null text5 null null su3 null null null null null
John
-
How to filter the result with a where clause clause?
Hello
I have a nice sql query. I would like to include a where clause with a joker clause.
If the user selects for example a "AGENT_ID", then where clause would include the AGENT_ID, otherwise, every thing would appear.
The WHERE clause:SELECT "FICHE"."FICHE_ID" "FICHE_ID", "FICHE"."AGENT_ID" "AGENT_ID", "FICHE"."EQUIPE_ID" "EQUIPE_ID", "FICHE"."DATE_ACTIVITE" "DATE_ACTIVITE", "FICHE"."DATE_CREATION" "DATE_CREATION", "FICHE"."TYPE_FICHE" "TYPE_FICHE", "FICHE"."FICHE_CREE_PAR" "FICHE_CREE_PAR", "FICHE"."TOTAL_HEURES" "TOTAL_HEURES", "FICHE"."TOTAL_HEURES_EXCEPTIONNELLES" "TOTAL_HEURES_EXCEPTIONNELLES", "FICHE"."DATE_MODIFICATION" "DATE_MODIFICATION" FROM "FICHE"
WHERE AGENT_ID = ' * ' if nothing is selected.
WHERE AGENT_ID = "4290" If an agent ID is selected.
Hope I'm clear that English is not my mother tongue.
Thanks for you help.
ChristianHello
Try this
WHERE "FICHE".AGENT_ID like NVL(:val, '%')
see you soon
VT
Maybe you are looking for
-
How to find RAM on Satellite Pro M40x slot?
Hi all I spent my entire day to find a built in RAM to replace with 1 new but unfortunately and unfortunately I can not find built-in RAM.I removed the keyboard, but there is that wireless card that I see here. Apartment for her I can't RAM. Can some
-
I have 8 bays on the front of my VI. I created refnum for each table. I build an array of these refnums and pass this array to a Subvi. LabVIEW is cast some the refnums and not others as evidenced by the red dot on the table element to build. The ber
-
Hello In the first sorry for my English. I am not bilingual, but I'll try to understand! When I opened my laptop, a message appears to tell me that step 3 of 3 for download as an update. A few minutes later, it is write is closed, but the computer re
-
Scanner error message: 8, [(0.18,-2147467259)]
Have: HP Photosmart e-All-in-One Printer - D110a, WiFi connectedSerial number: [personal information]Product number: CN731A After scanning and output of the utility and then back for another scan, so try to use looks like this: "Scan cannot because a
-
Is it possible to know the event of scrolling down
I'm doing a function to automatically load the data if ListView is already scrolled down so that I want to get this trigger. But I don't have the solution. Does anyone know the idea or any sample? Thank you.