Reg: Query with UNION
Dear all,
I have two tables
TABLE A (A_DATE, COLA1, COLA2)
TABLE B (B_DATE)
A_DATE = B_DATE
Examples of tables:
TABLE A (11 selected lines)
A_DATE | COLA1 | COLA2 |
---|---|---|
03/01/2013 | 54 | VAL76 |
04/01/2013 | 11 | VAL78 |
04/01/2013 | 11 | VAL22 |
04/01/2013 | 74 | VAL22 |
04/02/2013 | 15 | VAL45 |
04/02/2013 | 11 | VAL22 |
04/03/2013 | 44 | VAL22 |
04/03/2013 | 71 | VAL73 |
04/04/2013 | 99 | VAL13 |
04/05/2013 | 11 | VAL22 |
04/05/2013 | 11 | VAL23 |
TABLE B (01 April-30 April)
B_DATE |
---|
04/01/2013 |
04/02/2013 |
04/03/2013 |
04/04/2013 |
(condition 1: month: April)
AND
condition 2: CALA1-> 11
AND
condition 3: COLA2-> VAL22)
I need to display all records for the months April to TABLE A,.
If the documents are not present in TABLE A for every 30 days, I need to display null, by reading DATE information in TABLE B
Expected results (sample)
Date | COLA1 | COLA2 |
---|---|---|
04/01/2013 | 11 | VAL22 |
04/02/2013 | 11 | VAL22 |
04/03/2013 | ||
04/04/2013 | ||
04/05/2013 | 11 | VAL22 |
Currently I have the following query
Select A_DATE, COLA1, COLA2 from TABLEA
where COLA1 = 11 and COLA2 in ('VAL22') and A_DATE between ' 2013-04-01 00:00:00.0' AND ' 00:00:00.0' 2013-04-30
Union of all the
Select B_DATE, null, null from TABLEB if date between ' 2013 - 04 - 01 00:00:00.0' AND ' 00:00:00.0' 2013-04-30
But I'm the duplicate records for the values in TABLE a.
Output current (sample)
Date | COLA1 | COLA2 |
---|---|---|
04/01/2013 | 11 | VAL22 |
04/01/2013 | ||
04/02/2013 | 11 | VAL22 |
04/02/2013 | ||
04/03/2013 | ||
04/04/2013 | ||
04/05/2013 | 11 | VAL22 |
04/05/2013 |
I tried with UNION and UNION ALL, but getting the same result.
Hello
Try this:
Select b.B_DATE, a, COLA1, one, COLA2
from TABLEB b
the left join TABLEA a
On a.A_DATE = b.B_DATE
and COLA1 = 11
and COLA2 in ('VAL22')
where B_DATE between to_date('2013-04-01','yyyy-mm-dd') AND to_date('2013-04-30','yyyy-mm-dd')
----
Ramin Hashimzade
Tags: Database
Similar Questions
-
Hi all
I have two requests and I want to join this two query
The column of the report should be like this
1st requestitem_number WK_30 WE_31
2nd requestselect re.item_number, nvl(le.quantity,0) - nvl(re.quantity,0) WK_30 from BACKLOG_WEEK_WH_AFTR_ATP le, BACKLOG_ATP_GT_CW_IN re where le.item_number =re.item_number and to_number(substr(re.year_week,-2,2)) = to_number(to_char(sysdate,'IW'))+1
Thanks in advanceselect re.item_number, nvl(le.quantity,0) - nvl(re.quantity,0) WK_31 from BACKLOG_WEEK_WH_AFTR_ATP le, BACKLOG_ATP_GT_CW_IN re where le.item_number =re.item_number and to_number(substr(re.year_week,-2,2)) = to_number(to_char(sysdate,'IW'))+2
ConcerningHello
You are welcome.
I think that the best way to understand that is to show what data is generated at each stage...
1. we need to generate a list of lines that have every week, we are interested in swing on...
( SELECT to_number(to_char(sysdate,'IW')) + ROWNUM year_week_num FROM DUAL CONNECT BY LEVEL <= 5 ) row_gen YEAR_WEEK_NUM ------------- 30 31 32 33 34
2. must be added BACKLOG_WEEK_WH_AFTR_ATP lines in the calculations for the first week in the report
SELECT le.item_number, le.quantity, to_number(to_char(sysdate,'IW'))+1 year_week_num FROM BACKLOG_WEEK_WH_AFTR_ATP le UNION ALL SELECT re.item_number, -re.quantity, to_number(substr(re.year_week,-2,2)) year_week_num FROM BACKLOG_ATP_GT_CW_IN re / ITEM_NUMBE QUANTITY YEAR_WEEK_NUM ---------- ---------- ------------- ITEM_1 200 30 ITEM_2 600 30 ITEM_1 -200 30 ITEM_1 -100 33 ITEM_2 -300 30 ITEM_2 -200 32 ITEM_3 -800 30 ITEM_3 -400 34
3. we must now repeat weekly, generated by the request of row_gen against all of the item_numbers returned by the above query and match them if possible to get the amount. Where there is no entry in BACKLOG_WEEK_WH_AFTR_ATP or BACKLOG_ATP_GT_CW_IN for a number of the week, we should use 0 as the quantity. The Partition Outer Join does for us.
SQL> select 2 re.item_number, 3 row_gen.year_week_num, 4 NVL(re.quantity,0) qty 5 from 6 ( SELECT 7 to_number(to_char(sysdate,'IW')) + ROWNUM year_week_num 8 FROM 9 DUAL 10 CONNECT BY LEVEL <= 5 11 ) row_gen LEFT OUTER JOIN 12 ( SELECT 13 le.item_number, 14 le.quantity, 15 to_number(to_char(sysdate,'IW'))+1 year_week_num 16 FROM 17 BACKLOG_WEEK_WH_AFTR_ATP le 18 UNION ALL 19 SELECT 20 re.item_number, 21 -re.quantity, 22 to_number(substr(re.year_week,-2,2)) year_week_num 23 FROM 24 BACKLOG_ATP_GT_CW_IN re 25 ) re 26 PARTITION BY (re.item_number) 27 ON ( row_gen.year_week_num = re.year_week_num) 28 / ITEM_NUMBE YEAR_WEEK_NUM QTY ---------- ------------- ---------- ITEM_1 30 200 ITEM_1 30 -200 ITEM_1 31 0 ITEM_1 32 0 ITEM_1 33 -100 ITEM_1 34 0 ITEM_2 30 -300 ITEM_2 30 600 ITEM_2 31 0 ITEM_2 32 -200 ITEM_2 33 0 ITEM_2 34 0 ITEM_3 30 -800 ITEM_3 31 0 ITEM_3 32 0 ITEM_3 33 0 ITEM_3 34 -400 17 rows selected.
4. now, we have the base dataset that we need - she has all the amounts with the right directions so that we can simply add everything up as a sum of sumulative. That's what makes OVER(PARTITION BY re.item_number ORDER BY row_gen.year_week_num) SUM (NVL(re.quantity,0)) bit. He said baseically are all lines seen so far in the result set for each item number...
select re.item_number, row_gen.year_week_num, NVL(re.quantity,0) qty, SUM(NVL(re.quantity,0)) OVER(PARTITION BY re.item_number ORDER BY row_gen.year_week_num) quantity from ( SELECT to_number(to_char(sysdate,'IW')) + ROWNUM year_week_num FROM DUAL CONNECT BY LEVEL <= 5 ) row_gen LEFT OUTER JOIN ( SELECT le.item_number, le.quantity, to_number(to_char(sysdate,'IW'))+1 year_week_num FROM BACKLOG_WEEK_WH_AFTR_ATP le UNION ALL SELECT re.item_number, -re.quantity, to_number(substr(re.year_week,-2,2)) year_week_num FROM BACKLOG_ATP_GT_CW_IN re ) re PARTITION BY (re.item_number) ON ( row_gen.year_week_num = re.year_week_num) / ITEM_NUMBE YEAR_WEEK_NUM QTY QUANTITY ---------- ------------- ---------- ---------- ITEM_1 30 200 0 ITEM_1 30 -200 0 ITEM_1 31 0 0 ITEM_1 32 0 0 ITEM_1 33 -100 -100 ITEM_1 34 0 -100 ITEM_2 30 -300 300 ITEM_2 30 600 300 ITEM_2 31 0 300 ITEM_2 32 -200 100 ITEM_2 33 0 100 ITEM_2 34 0 100 ITEM_3 30 -800 -800 ITEM_3 31 0 -800 ITEM_3 32 0 -800 ITEM_3 33 0 -800 ITEM_3 34 -400 -1200
5. we can now rotate these data in columns - however, there is a small problem. For points 1 and 2 we have 2 lines for the week 30, running in the quantity column total is the same for both because the two lines appear at the same point in the game as defined by the order by clause. This means before rotate us, we must select one of the lines - or the other will do, they are both correct. If we do not have, the effect will be to double the cumulative sum (for point 1 is 0, so it does not appear) for this, we can use the ROW_NUMBER function...
select re.item_number, row_gen.year_week_num, NVL(re.quantity,0) qty, SUM(NVL(re.quantity,0)) OVER(PARTITION BY re.item_number ORDER BY row_gen.year_week_num) quantity, ROW_NUMBER() OVER(PARTITION BY re.item_number, row_gen.year_week_num ORDER BY NULL) rn from ( SELECT to_number(to_char(sysdate,'IW')) + ROWNUM year_week_num FROM DUAL CONNECT BY LEVEL <= 5 ) row_gen LEFT OUTER JOIN ( SELECT le.item_number, le.quantity, to_number(to_char(sysdate,'IW'))+1 year_week_num FROM BACKLOG_WEEK_WH_AFTR_ATP le UNION ALL SELECT re.item_number, -re.quantity, to_number(substr(re.year_week,-2,2)) year_week_num FROM BACKLOG_ATP_GT_CW_IN re ) re PARTITION BY (re.item_number) ON ( row_gen.year_week_num = re.year_week_num) / ITEM_NUMBE YEAR_WEEK_NUM QTY QUANTITY RN ---------- ------------- ---------- ---------- ---------- ITEM_1 30 200 0 1 ITEM_1 30 -200 0 2 ITEM_1 31 0 0 1 ITEM_1 32 0 0 1 ITEM_1 33 -100 -100 1 ITEM_1 34 0 -100 1 ITEM_2 30 -300 300 1 ITEM_2 30 600 300 2 ITEM_2 31 0 300 1 ITEM_2 32 -200 100 1 ITEM_2 33 0 100 1 ITEM_2 34 0 100 1 ITEM_3 30 -800 -800 1 ITEM_3 31 0 -800 1 ITEM_3 32 0 -800 1 ITEM_3 33 0 -800 1 ITEM_3 34 -400 -1200 1
6. so now that we have a way to select one of the duplicate lines, we can move forward a pivot data by ensuring that us choose only 'first' line for each element for each week...
SELECT item_number, SUM ( CASE WHEN year_week_num = to_number(to_char(sysdate,'IW'))+1 THEN quantity END ) plus_1, SUM ( CASE WHEN year_week_num = to_number(to_char(sysdate,'IW'))+2 THEN quantity END ) plus_2, SUM ( CASE WHEN year_week_num = to_number(to_char(sysdate,'IW'))+3 THEN quantity END ) plus_3, SUM ( CASE WHEN year_week_num = to_number(to_char(sysdate,'IW'))+4 THEN quantity END ) plus_4, SUM ( CASE WHEN year_week_num = to_number(to_char(sysdate,'IW'))+5 THEN quantity END ) plus_5 FROM ( select re.item_number, row_gen.year_week_num, SUM(NVL(re.quantity,0)) OVER(PARTITION BY re.item_number ORDER BY row_gen.year_week_num) quantity, ROW_NUMBER() OVER(PARTITION BY re.item_number, row_gen.year_week_num ORDER BY NULL) rn from ( SELECT to_number(to_char(sysdate,'IW')) + ROWNUM year_week_num FROM DUAL CONNECT BY LEVEL <= 5 ) row_gen LEFT OUTER JOIN ( SELECT le.item_number, le.quantity, to_number(to_char(sysdate,'IW'))+1 year_week_num FROM BACKLOG_WEEK_WH_AFTR_ATP le UNION ALL SELECT re.item_number, -re.quantity, to_number(substr(re.year_week,-2,2)) year_week_num FROM BACKLOG_ATP_GT_CW_IN re ) re PARTITION BY (re.item_number) ON ( row_gen.year_week_num = re.year_week_num) ) WHERE rn = 1 GROUP BY item_number
You need not add a join between BACKLOG_WEEK_WH_AFTR_ATP and BACKLOG_ATP_GT_CW_IN, because we are all summed up in the article number and all item numbers, we have selected two tables. The aggregation ensures that the quantities are added together against the item number.
HTH
David
-
Report with the query with union and parameters
Hello
We have an obligation to create a report with the request, which is the union and parameters.
I intend to create a database for the report based on a query. But the problem here is that the way to pass parameters in the query.
Request is something like that
Select x.a, x.b, x.c
x
where x.year =: para1
and x.status = 'A '.
Union of all the
Select x.a, x.b, x.c
x
where x.year =: para1 - 1
and (x.status = 'c' and x.date =: para2 or x.status = 'I' and x.date < =: para2)
Here x.year in the first select statement must be equal to: para1 and second select statement, it should be: para - 1.
How this requirement can be achieved?
Client don't want to separate worksheet, a parameter and another for the actual data that I tried with sys_context and it worked. But the client wants the result in a single sheet only... So I need to change their approach.
Help, please.
Thank youHello
Another option is to convert the request so that you will have the items from the selection
for example on the query you provided that you can use:Select 'Curr' rec_type, x.a, x.b, x.c, x.year, x.date, x.status
x
where x.status = "A".
Union of all the
Select 'Prev' rec_type, x.a, x.b, x.c, x.year, x.date, x.status
x
where x.status in ('c', 'I')then, in the workbook, you will be able to create conditions such as:
rec_type = 'Curr' and year =: para1rec_type = 'Prev' and year =: para1-1
rec_type = 'Prev' and (status = 'c' and date =: para2 or status = 'I' and date)<=>=>Tamir
-
Rewrite the query with joins, and group by
Hello
It's an interview question.
Table names: bookshelf_checkout
virtual library
And the join condition between these two tables is title
We need to rewrite under request without using the join condition and group by clause?
When I was in College, I read most of SELECT statements can be replaced by operations base SQL (DEFINE the OPERATORS). Now, I am rewriting the query with SET operators, but not able to get the exact result.SELECT b.title,max(bc.returned_date - bc.checkout_date) "Most Days Out" FROM bookshelf_checkout bc,bookshelf b WHERE bc.title(+)=b.title GROUP BY b.title;
Kindly help me on this.
Thank you
SuriSomething like that?
1 WITH books AS ( 2 SELECT 'title 1' title FROM dual UNION ALL 3 SELECT 'title 2' FROM dual UNION ALL 4 SELECT 'title 3' FROM dual ), 5 bookshelf AS ( 6 SELECT 'title 1' title, DATE '2012-05-01' checkout_date, DATE '2012-05-15' returned_date FROM dual UNION ALL 7 SELECT 'title 1' title, DATE '2012-05-16' checkout_date, DATE '2012-05-20' returned_date FROM dual UNION ALL 8 SELECT 'title 2' title, DATE '2012-04-01' checkout_date, DATE '2012-05-15' returned_date FROM dual ) 9 SELECT bs.title, MAX(bs.returned_date - bs.checkout_date) OVER (PARTITION BY title) FROM bookshelf bs 10 UNION 11 (SELECT b.title, NULL FROM books b 12 MINUS 13* SELECT bs.title, NULL FROM bookshelf bs) SQL> / TITLE MAX(BS.RETURNED_DATE-BS.CHECKOUT_DATE)OVER(PARTITIONBYTITLE) ------- ------------------------------------------------------------ title 1 14 title 2 44 title 3
Lukasz
-
How can I fix this. REG QUERY "HKLM\SOFTWARE\Microsoft.
HELP... Can someone please tell me what this means and how can I fix. REG QUERY 'HKLM\SOFTWARE\Microsoft NT\CurrentVersion\AppcompatFlags\UpgrapeExperienceIndicators' / v UpgEx: finderstr UpgEx ERROR: the system was unable to find the specified registry or the value key.
How does this relate to the features of Windows Update (or recovery)?
Did you mean "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\ExperienceIndicatorsUpgrade... » ?
Is this a computer Win7 Pro or Ultimate?
Is this the same computer (not the same problem) in one or two of these previous discussions of yours?...
-
Hello
I'm trying to use Reg Query to review the contents of a registry key. More precisely
- HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify
I just want to know what are the subkeys. I expect to be
- IconStreams and
PastIconsStream
Since they are both of type reg_binary, when I do this query I have also all binary data as well, make very large output.Is there a way to simply retrieve/request which is in the field/column name and not the data column/field? I tried the /k options and /v who gave me errors, which I interpreted in the sense I was their use either wrong or they are not used in this instance.
There is not a lot of examples out there and most of repeat them what you find when you use /?.
Thank you.
Hello
The question you posted would be better suited in the MSDN Forums. I would recommend posting your query in the MSDN Forums.
http://social.msdn.Microsoft.com/forums/en-us/windowsgeneraldevelopmentissues
-
Hello
I'm trying to use Reg Query to review the contents of a registry key. More precisely
- HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify
I just want to know what are the subkeys. I expect to be
- IconStreams and
PastIconsStream
Since they are both of type reg_binary, when I do this query I have also all binary data as well, make very large output.
Is there a way to simply retrieve/request which is in the field/column name and not the column/field data ? I tried the /k options and /v who gave me errors, which I interpreted in the sense I was their use either wrong or they are not used in this instance.
There is not a lot of examples out there and most of repeat them what you find when you use /?.
Thank you.
Hello
The question you posted would be better suited in the MSDN Forums. I would recommend posting your query in the MSDN Forums.
http://social.msdn.Microsoft.com/forums/en-us/windowsgeneraldevelopmentissues
-
More than 1 SQL query with checkbox and error invalid number report
Hi all
I have two SQL query reports that each has an apex_item.checkbox and two processes for each report. A report/process works very well. It gives me an error of invalid number.
In addition, another query SQL (editable report) gives me the following error when using the Multi line process, delete.
ORA-06502: PL/SQL: digital or value error: character number conversion
error ORA-06502: PL/SQL: digital or value error: character number conversion
errorOk When I got a report from SQL query (with box and a process) and the query SQL (editable report) everything worked. It stopped working when I added another SQL query report (with box and a process).
A SQL query has the following in my query: apex_item.checkbox(3,email_id,'UNCHECKED') ""
The other SQL query has the following: apex_item.checkbox(2,b.file_id,'UNCHECKED') ""
Any help will be greatly appreciated,
Sylvia
Hi Reema,
I've recreated the region and now it works!
Thank you for this, looking at
Sylvia
-
Write a SQL query with lines in columns
All the
I need help in writing a SQL query with lines in columns, let give u an example...
drop table activity;
CREATE TABLE 'ACTIVITY '.
(
"PROJECT_WID" NUMBER (22.0) NOT NULL,
VARCHAR2 (150 CHAR) "PROJECT_NO."
VARCHAR2 (800 CHAR) 'NAME '.
);
Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1683691, '10007', 12-121');
Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1684994, '10008', 12-122');
Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1686296, '10009', 12-123');
Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (2225222, '9040', 12-124');
drop table lonet;
CREATE TABLE 'LONET.
(
VARCHAR2 (150 CHAR) "NAME."
NUMBER OF THE "ROOT."
VARCHAR2 (150 CHAR) "ENTRYVALUE".
);
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("GAC", 1683691, "LDE");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('NAM', 1683691, 'LME');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('BAG', 1683691, 'ICE');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1683691, 'IKE');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('NAM', 1686291, "QTY");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1686291, 'MAX');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("GAC", 1684994, "MTE");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1684994, 'MAC');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('FMT', 1684994, 'NICE');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('FMR', 1684994, 'RAY');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('BAG', 1686296, "CAQ");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("PAP", 1686296, "QAQ");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("VANESSA", 1686296, "THEW");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("ANDR", 1686296, "REYL");
commit;
Link: activity.project_wid = lonet.root
look like output
Project_wid Project_no NAME GAC NAM BAG RAC 1683691 10007 12-121 LDE LME LCE LKE 1684994 10008 12-122 MTE null null MAC 1686296 10009 12-123 null null CAQ QAQ 2225222 9040 12-124 null null null null two problems, in that I am running
1. I dono how simply we can convert rows to columns
2. for root = 1683691, there are double NAM and RAC in lonet table... ideally these data should not be there, but since its here, we can take a MAX so that it returns a value
3. There are undesirables who should be ignored
Once again my thought process is that we join the activity and 4 alias table lonet.
ask for your help in this
Thank you
Hello
This is called pivoting.
Here's a way to do it:
WITH relevant_data AS
(
SELECT a.project_wid, a.project_no, b.SID
, l.name AS lonet_name, l.entryvalue
Activity one
LEFT OUTER JOIN lonet l.root = a.project_wid l
)
SELECT *.
OF relevant_data
PIVOT (MAX (entryvalue)
FOR lonet_name IN ("GAC" IN the gac
"NAM" AS nam
'BAG' IN the bag
"RAC" AS cars
)
)
ORDER BY project_wid
;
Output:
PROJECT_WID PROJECT_NO GAC NAM BAG RAC NAME
----------- ---------- ---------- ---------- ---------- ---------- ----------
1683691 12 - 10007 121 LDE LME LCE LKE
1684994 MAC MTE 10008 12-122
1686296 12 - 10009 123 QAC QAQ
2225222 9040 12 - 124
To learn more about swivel, see the FAQ in the Forum: Re: 4. How can I convert rows to columns?
Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!
-
help me out with a query with an output that has own text.
help me out with a query with an output that has own text.
For example select name from tbl_name
Ben "is my name"-> should be the output
Hello
3cc59f7b-B8C1-4EFA-8385-e0d8720a689c wrote:
help me out with a query with an output that has own text.
For example select name from tbl_name
Ben "is my name"---> should be the output
Sorry, it is not clear what you want.
If the table contains only "Ben", then you can get the output above using a query like this:
SELECT name. '' my name is' ' AS name_plus
FROM tbl_name;
I hope that answers your question.
If this isn't the case, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements), and the results you want from this data.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum: https://forums.oracle.com/message/9362002#9362002
-
Can I do a query with a varchar2 or other inside OF?
How can I do a query with a Variable (varchar) inside OF?
example:
Select * from: var;
I received the error message: "invalid table name".
declare
n number;
table-name varchar2 (30): = "double";
Start
run immediately 'count (*) select "| table_name in n;
dbms_output.put_line (n);
end;
/
-
Select the query with the level line list where the clause
Hi all
I am creating a tabular presentation based on a SQL query that has a list of selection based on a query with a where clause clause that refers to a column in the original SQL query.
The situation is, I have a table that stores the client_id, source_id, and build_id, lets call it client_source. I have a second table, build_source, containing source_id and build_id, one to many relations between the two (1 source_id could have build_id 1-7).
Using a tabular presentation, I want to select the correspondent build_id to use in client_source, but the selection list should contain only the build_id for this particular source_id of lines.
Here is an example of the SQL source of tabular presentation;
Select
s.ROWID,
s.CLIENT_ID,
s.SOURCE_ID,
APEX_ITEM. SELECT_LIST_FROM_QUERY (1, s.BUILD_ID,)
"Select display b.build_id, b.build_id return.
b build_source where b.source_id = s.SOURCE_ID ') lst
of s client_source
what I want to achieve, it's as source_id "BOLD" match fields. When the query is built this way, I get an error of "invalid identifier" Oracle on s.SOURCE_ID during execution.
Is there some special tags to be used to refer to the external column? I must be missing something because this looks like a pretty mundane problem.
I am running on 4.1.0.00.32, on an Oracle 10 g release 10.2.0.4.0 Server Express request.
I look forward to useful responses!
See you soon,.
Jason
Published by: 1005131 on May 9, 2013 19:02Your selection by query list receives a static SQL. That SQL can't "see" the value of your s.source_id.
But it would work like this:
where b.source_id = ' | s.SOURCE_ID)You would be the value for the SQL concatenation. It is not ideal, but it will work.
Jorge
-
SQL query with terms and calculations?
Hello
How do I create a query with terms and calculations?
For example, I have this table
Start | End | At work | Mandatory
------------------------------------------------------------------------------------
1ST JANUARY 13 | JANUARY 11, 13. Office | 1
JANUARY 14, 13. 25 JANUARY 13 | Ministry of the Interior. 0
04-MRZ-13 | 15-MRZ-13 | Office | 0
FEBRUARY 11, 13. FEBRUARY 22, 13. Office | 1
Now, if the workplace of the column = office and required column = 0
the new 'price' column should calculate: (end-start) * $25.00
and if workplace = Office and required column = 1
the 'price' column must calculate: (end-start) * $20.60
any other $0.00
I tried with the case statement, but I didn't know how
to calculate my values and display in the virtual column 'price '.
Something like
case
When Working_Place = 'Office' and mandatory = 1
then...
else ' 0.00'. "
end PRICE
?????
Or is that not possible?
Published by: DB2000 on 12.03.2013 05:09Use CASE:
select start_dt, end_dt, working_place, mandatory, case when working_place = 'Office' and mandatory = 0 then (end_dt - start_dt) * 25 when working_place = 'Office' and mandatory = 1 then (end_dt - start_dt) * 20.60 else 0 end price from tbl / START_DT END_DT WORKING_PLA MANDATORY PRICE --------- --------- ----------- ---------- ---------- 01-JAN-13 11-JAN-13 Office 1 206 14-JAN-13 25-JAN-13 Home Office 0 0 04-MAR-13 15-MAR-13 Office 0 275 11-FEB-13 22-FEB-13 Office 1 226.6 SQL>
SY.
-
A simple query with as wrong return result
Hello
I run a simple query with like.
If I use the parameter I get incorrect results.
If I use the request without parameter results are ok.
My script:
ALTER SESSION SET NLS_SORT = BINARY_CI;
ALTER SESSION SET NLS_COMP = LINGUISTIC;
-drop table abcd;
create table abcd (col1 varchar2 (10));
INSERT INTO VALUES ABCD ('122222');
insert into abcd values ('111222');
SELECT * FROM ABCD WHERE COL1 LIKE: 1. -bad result with 12%
/*
COL1
----------
122222
* 111222 *.
*/
"Select * ABCD where col1 like 12%; -result ok
/*
COL1
----------
122222
*/
I use Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production
and query, run in Oracle SQL Developer 3.1.07.I think it's just a bug, and it is set to 11.2.0.3:
11.2.0.1:
DB11.2.0.1>> select * from v$version where rownum=1; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production 1 row selected. DB11.2.0.1>> ALTER SESSION SET NLS_SORT=BINARY_CI; Session altered. DB11.2.0.1>> ALTER SESSION SET NLS_COMP=LINGUISTIC; Session altered. DB11.2.0.1>> create table abcd (col1 varchar2(10)); Table created. DB11.2.0.1>> INSERT INTO ABCD VALUES ('122222'); 1 row created. DB11.2.0.1>> insert into abcd values ('111222'); 1 row created. DB11.2.0.1>> VARIABLE A1 VARCHAR2(10); DB11.2.0.1>> EXEC :A1 := '12%'; PL/SQL procedure successfully completed. DB11.2.0.1>> SELECT * FROM ABCD WHERE COL1 LIKE :A1; COL1 ---------- 122222 111222 2 rows selected.
11.2.0.3:
DB11.2.0.3>> select * from v$version where rownum=1; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production 1 row selected. DB11.2.0.3>> ALTER SESSION SET NLS_SORT=BINARY_CI; Session altered. DB11.2.0.3>> ALTER SESSION SET NLS_COMP=LINGUISTIC; Session altered. DB11.2.0.3>> create table abcd (col1 varchar2(10)); Table created. DB11.2.0.3>> INSERT INTO ABCD VALUES ('122222'); 1 row created. DB11.2.0.3>> insert into abcd values ('111222'); 1 row created. DB11.2.0.3>> VARIABLE A1 VARCHAR2(10); DB11.2.0.3>> EXEC :A1 := '12%'; PL/SQL procedure successfully completed. DB11.2.0.3>> SELECT * FROM ABCD WHERE COL1 LIKE :A1; COL1 ---------- 122222 1 row selected.
Kind regards
Sayan Malakshinov
http://orasql.org -
Please suggest a select query / under query with using any routines or
source table: three columns ORIGIN, DESTINATION, MILES
Origin Destination Miles
Sydney Melbourne 1000
Perth, Adelaide 3000
Canberra Melbounre 700
Melbourne Sydney 1000
Brisbane Sydney 1000
Perth, Darwin 4000
Sydney, Brisbane 1000
out put: three columns ORIGIN, DESTINATION, MILES
Duplicate routes should be ignored, so the output is
Origin Destination Miles
Sydney Melbourne 1000
Perth, Adelaide 3000
Canberra Melbounre 700
Brisbane Sydney 1000
Perth, Darwin 4000
Please suggest a select query / under query with using subroutines or functions/pkgs to get put out table.Hello
user9368047 wrote:
... Please suggest a select query / under query with using subroutines or functions/pkgs to get put out table.Why? If the most effective way to achieve the desired results is to use a function, why would you not use it?
Here's a way, without all the features:
SELECT a.* FROM source_table a LEFT OUTER JOIN source_table b ON a.origin = b.destination AND a.destination = b.origin AND a.miles = b.miles WHERE b.origin > a.origin -- Not b.origin > b.origin OR b.origin IS NULL ;
If you would care to post CREATE TABLE and INSERT statements for your sample data, and then I could test this.
Published by: Frank Kulash, November 6, 2012 19:39
Fixed WHERE after MLVrown clause (see below)
Maybe you are looking for
-
My Macbook Pro won't let me put my password, after it has been locked in icloud
Hello. I have a Macbook pro to the end of 2013. I locked using icloud with a four-digit code. I forgot the code and had several attempts trying to remember her and now I think I found it, but it won't let me put the code in another attempt. the messa
-
update to 9.3.5 iPad mini
iOS users have recently been warned to proceed with an upgrade to iOS 9.3.5 due to a security problem. Our iPad Mini is actually run 9.3.4 but when we try to update via the "Général" menu, it is looking for an update constantly. We tried several time
-
Firefox don't support not any page after some time.
I'm having a problem with firefox while surfing after a while. For example, during the first 15 minutes, there is no problem, after a while firefox does not load any page, I have to close and reopen again to make it work. While firefox does not load,
-
you will need to upgrade to Outlook express. How to do it please?
I have been using XP for many years and am very happy with it. I have been using Outlook Express for many years. Now upgrade to a newer system, while always remaining with the good old, something that resembles XP. How can I set up please? Thanks in
-
Can't read converted YouTube music files in Windows media player
Original title: windows media player I downloaded music videos from youtube and convert them to mp3. I can not play on wmp11