selection of lines corresponding to two columns with two entry tables
I have a table with two columns int primary key tab1. id1 and id2.Now I have two created two tables of figures: array1 {1, 2, 3,...} and {0, 1, 0,...} array2 Arrays have the same length.
I want to do a select:
Select * from tab1 where tab1.id1 = array1.column_value and tab1.id2 = array2.column_value;
If I want to receive 13 lines with this request, I had 169 because it tries to match all the different combinations in the tables.
If I do it with a loop for:
for i of array1
loop
Select * from tab1 where tab1.id1 = array1 (i) and tab1.id2 (i);
end
That should illustrate what I want to do, I just thought it would be faster if I could do it without a loop, do not use the pl/sql. Can it be done? If not, should I use a loop for with bulk collect somehow?
SQL> with t as (
select 1 id1, 0 id2 from dual union all
select 2, 0 from dual union all
select 3, 0 from dual union all
select 4, 1 from dual
)
--
--
select id1, id2
from t,
(select rownum rn1, a1.* from table (sys.odcinumberlist (1, 2, 3, 4)) a1) a1, --- array1
(select rownum rn2, a2.* from table (sys.odcinumberlist (0, 1, 0, 1)) a2) a2 --- array2
where (id1, id2) in ( (a1.column_value, a2.column_value)) and rn1 = rn2
/
ID1 ID2
---------- ----------
1 0
3 0
4 1
3 rows selected.
Tags: Database
Similar Questions
-
place a select query calculation in a different column in the same table
How can I put my calculation result in a column named within the same table?
I have a table called: dgpercentagedatachart
I use the columns of this dgpercentagedatachart: totalcecrating divided by lowestfeederrating times 100 to get the percentage
In the query, I gave the result the Alias of the cal
What I want is to put this result in my application or my calculation (in percentage) in my column "percent" on my table of dgpercentagedatachart vacuum.
How can I configure this syntax?
This is the select query, I came with:
Select dgpercentagedatachart.totalcecrating, dgpercentagedatachart.lowestfeederrating,.
100.00*dgpercentagedatachart.totalcecrating/dgpercentagedatachart.lowestfeederrating as cal
of dgpercentagedatachart;
Here are the results:
CAL lowestfeederrating Totalcecrating
8,978 7.48166666666666666666666666666666666667 120
30.951 25.7925 120
5.04 120 4.2
Hello
2685870 wrote:
How can I put my calculation result in a column named within the same table?
I have a table called: dgpercentagedatachart
I use the columns of this dgpercentagedatachart: totalcecrating divided by lowestfeederrating times 100 to get the percentage
In the query, I gave the result the Alias of the cal
What I want is to put this result in my application or my calculation (in percentage) in my empty column '%' on my table of dgpercentagedatachart .
How can I configure this syntax?
This is the select query, I came with:
Select dgpercentagedatachart.totalcecrating, dgpercentagedatachart.lowestfeederrating,.
100.00*dgpercentagedatachart.totalcecrating/dgpercentagedatachart.lowestfeederrating as cal
of dgpercentagedatachart;
Here are the results:
CAL lowestfeederrating Totalcecrating
8,978 7.48166666666666666666666666666666666667 120
30.951 25.7925 120
5.04 120 4.2
To change an existing column in a table, you can use the UPDATE or MERGE, instructions like this:
UPDATE dgpercentagedatachart
Percentage of VALUE = 100,00 * totalcecrating
/ lowestfeederrating
;
Noramlly, tables is not redundant columns like this. If percent can always be calculated from other columns, then it is probably better to calculate at run time and store it in the database, where you will have to be updated each time the columns it depends on change. You can use a view to avoid having to encode them the calculation.
If you really don't want a column that can be calculated in the same lines other columns, then use a virtual column (if you use Oracle 11 or higher).
I hope that answers your question.
If this isn't the case, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
If you ask on a DML statement, such as UPDATE, the sample data will be the content of the or the tables before the DML, and the results will be the State of the or the tables changed when it's all over.
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: Re: 2. How can I ask a question on the forums?
-
Show data as a percentage of column with a static table
Hello
I have a problem of calculating one percent in a table. I have two columns in the criteria tab:
Departments and degree
I need an extra column % calc total departments for each Department. I know that I can do with PivotTable, create a new column and put: view-> data as per cent of-> column but I do with the static table.
Is possible to do?
Thank you!!!Alex,
You can try the following example here:
http://www.biconsultinggroup.com/knowledgebase.asp?CategoryID=198&SubCategoryID=364
by using the sum (measure of the size attribute)
This should give you access total general in the report in a column, you can drift % of.
HTH, if it is correct, please mark answered / reward points, as you see fit to do!
Alastair -
Programmatically change the selected cell/line of control multi-column listbox
I want to programmatically change the selected cell of a multicolumn list box whose selection Mode is set to highlight the whole line. I would use this to highlight the line whatever the list box, I chose to. It would work the same way if the user has clicked on a line to select and highlight that particular line. Set Active cell does not fulfill this.
Steve
Try to use the property value; p
-
I have a column with two values, separated by a space, in each line. How do I create 2 new columns with the first value in one column and the second value in another column?
Add two new columns after than the original with space separated values column.
Select cell B1 and type (or copy and paste it here) the formula:
= IF (Len (a1) > 0, LEFT (A1, FIND ("", A1) −1), ' ')
shortcut for this is:
B1 = if (Len (a1) > 0, LEFT (A1, FIND ("", A1) −1), ' ')
C1 = if (Len (a1) > 0, Member SUBSTITUTE (A1, B1 & "", ""), "")
or
the formula of the C1 could also be:
= IF (Len (a1) > 0, RIGHT (A1, LEN (A1) −FIND ("", A1)), "")
Select cells B1 and C1, copy
Select cells B1 at the end of the C column, paste
-
How to fill a column with numbers and maintain when adding or deleting lines?
So far, I've discovered two ways to fill a column with the number:
1. Enter '1' in a single cell, '2' in the one below, select both, and then use the yellow dot to drag down - it will do the rest.
2 create a formula such as 'A2 + 1' and drag also.
However, in both cases it will work if I manually this continues to do for each newly added line at the bottom. Now, that alone would not be that big of a problem if it wasn't for the fact that I'm working with a table where the lines can be added among other rows in the future.
Having said that, could someone please tell me how to create a column with a number that will increase automatically? I mean - if I add a new line between line 56 and 57, I want the new line to have a '57"in it, and the" old 57 "would now be"58"and so on." " I don't want to drag the whole column, which can be hundreds if not more than a thousand lines.
Try to put this in the cells in the column:
= ROW()
In the formula, you can add or subtract a number if necessary to get the starting number that you need.
SG
-
Numbering of the lines based on two columns
Hello world
I´d would like to know if there is a way to achieve the numbering shown in the second table below indicating only Oracle native functions, like ROW_COUNT() on the partition, etc.
I m using Oracle 10 g.
The logic used is:
From 1, increment one each time that the ORIGIN is identical to the FIRST ORIGIN of the line (ID) group.
In order to compare the ORIGIN of each line with the FIRST ORIGIN of the group, I used the function LAG to create a column that will be the FIRST ORIGIN of the value in the group.ID ORIGIN DESTINATION ORDER ------------------------------------ 1 A B 1 1 B A 2 1 A B 3 1 B C 4 1 C A 5 ID ORIGIN DESTINATION ORDER NUMBERING -------------------------------------------------- 1 A B 1 1 1 B A 2 1 1 A B 3 2 1 B C 4 2 1 C A 5 2
However, I was not able to number the lines as shown above (column NUMBERING).
Any help will be much appreciated.
--------------------------------------------------------------------------------------------------------------
Test query:WITH T AS ( SELECT 1 ID, 'A' ORIGIN, 'B' DESTINATION, 1 ORDERING FROM DUAL UNION ALL SELECT 1 ID, 'B' ORIGIN, 'A' DESTINATION, 2 ORDERING FROM DUAL UNION ALL SELECT 1 ID, 'A' ORIGIN, 'B' DESTINATION, 3 ORDERING FROM DUAL UNION ALL SELECT 1 ID, 'B' ORIGIN, 'C' DESTINATION, 4 ORDERING FROM DUAL UNION ALL SELECT 1 ID, 'C' ORIGIN, 'A' DESTINATION, 5 ORDERING FROM DUAL ) SELECT T.ID , T.ORIGIN , T.DESTINATION , T.ORDERING , LAG (T.ORIGIN, T.ORDERING -1, 0) OVER (PARTITION BY T.ID ORDER BY T.ID , T.ORDERING) FIRST_ORIGIN_OF_GROUP FROM T ORDER BY T.ID , T.ORDERING
Hello
Here's one way:
WITH got_first_origin AS ( SELECT id, origin, destination, ordering , FIRST_VALUE (origin) OVER ( PARTITION BY id ORDER BY ordering ) AS first_origin FROM t ) SELECT id, origin, destination, ordering , COUNT ( CASE WHEN origin = first_origin THEN 1 END ) OVER ( PARTITION BY id ORDER BY ordering ) AS numbering FROM got_first_origin ;
This assumes that the combination of id and order is unique. Within an id, you place your order does not have to be consecutive integers, or something like that.
Analytical functions cannot be nested (the argument of the function of COUNTY anlytic can not call the analytical FIRST_VALUE function); The subquery is necessary.
You could do something with a LAG, as you have tried, rather than FIRST_VALUE, but you would still need a subquery, for the same reason. -
Today, I updated for Sierra and updated to the latest version of the Pages. Now I find that I am more able to select a line of text. When I try to do, I find myself with an insertion point where I stopped by selecting, but nothing is selected. This is a bug in the new version of pages or get my wrong settings?
You use a Wacom tablet by chance?
Solution: Press the shift key, just before stop selection. And Yes, that sounds like trouble in the Sierra.
-
I have a pdf form that has 4 columns, with each column having 28 check boxes and text between. I did so he goes by column, but when I do anything for a checkbox it takes it out of line. How can I keep that from happening?
You talk about the tab order? If Yes, go to Edit - Preferences - forms and make sure the box "Automatically adjust tab order when changing fields" is NOT checked.
-
Selection of lines with the range Paging VO
Hello
JDev 11.1.2.4
I created a VO based on an OA. I added a transitional attribute in the original Version, this attribute is named Selelected of type Boolean initialized to false (default value Expression: false-Expression of Refresh value: false). That VO appears as an af:table. The attribute is displayed as selectBooleanCheckbox. The VO is set with an access mode of range Paging and a size of 28.
< af:selectBooleanCheckbox value = "#{row.bindings.Selected.inputValue} '"
label = "#{bindings." VwRhdPortfolioTranWrkSend11.hints.Selected.label}.
required = "#{bindings." VwRhdPortfolioTranWrkSend11.hints.Selected.mandatory}.
shortDesc = "#{bindings." VwRhdPortfolioTranWrkSend11.hints.Selected.tooltip}"id ="it1' autoSubmit = 'true '.
valueChangeListener = "#{pageFlowScope.portfolioTransferBean.onWorkSelection}" >
< f: validator binding="#{row.bindings.Selected.validator}"/ >
< / af:selectBooleanCheckbox >
The table shows the 25 lines. The user clicks one of the checkbox to select a line. The valueChangeListener is called with the new value (auto submit = true) as expected. Then the user scroll down for another "page" in the table, new lines are displayed. Then it scrolls to the first page. The previous selected checkbox is reset as not selected. The selection is lost.
Is this expected behavior? If so how do you get a selection of lines with a VO of range paging.
Thank you
Try to create the transitional attribute in OT instead of VO.
See you soon
AJ
-
Select the line with the smallest Beach
Hello
I am trying to build a complex query...
He must select the line with the inner range...
I'll explain for example:
Location of poolsize ID value
1 32 8
2 40 6
3 42 8
4-36-3
I want to select the line where the fork between value and value + poolsize is shared also with the other location...
so:
1 is 32-40 (in A place)
2 is 40-46 (in place)
3 is 42-48 (location B)
4 is 36-39 (at location B)
4 is located at 1 (and there are different places...) so sql must return to the fourth line.
Any help will be appreciated!
Thank you
fcbmanHello
fcbman1899 wrote:
Hello
I am trying to build a complex query...
He must select the line with the inner range...I'll explain for example:
Location of poolsize ID value
1 32 8
2 40 6
3 42 8
4-36-3Whenever you have a problem, please post CREATE TABLE and INSERT statements for your sample data, in order to let the people who want to help you re-Ridge the problem and test their ideas.
See the FAQ forum {message identifier: = 9360002}I want to select the line where the fork between value and value + poolsize is shared also with the other location...
so:
1 is 32-40 (in A place)
2 is 40-46 (in place)
3 is 42-48 (location B)
4 is 36-39 (at location B)4 is located at 1 (and there are different places...) so sql must return to the fourth line.
To find all the rows that are within the range of at least one other line with another location:
SELECT * FROM table_x m WHERE EXISTS ( SELECT 1 FROM table_x WHERE location != m.location AND value <= m.value AND value + poolsize >= m.value + m.poolsize ) ;
When you talk of the "" * most * inner range ", do you mean that you might have another line, such as"
INSERT INTO table_x (id, vlue, poolsize, location) VALUES (5, 37, 1, 'C');
which is inside the range of id - 4, and that's why you wouldn't have id = 4? If so, include examples in the results and data sample yout. You can do this with a query CONNECT BY, or, depending on your version of Oracle, a WITH recursive clause.
-
LINES in COLUMNS with different values for each column (after division)
Hello
I have a table called summary where I produced, month, value,.
When I used select * tab, I get months jan, Feb, mar, Apr. I wrote a query to get the months(jan,feb,...) columns
SELECTmax (DECODE(ROWNUM,1,month)) Column1
+ Max (decode(rowNum,2,month)) table Column2 +.
as this up to 12 months
After that, I want to get the NEWVALUE for each month.
I wrote a query to get the value, but I get the value only for the first month, and for the rest, I get NULL values.
Select max (DECODE(ROWNUM,2,vallue)) Column1, Column2 of max table (DECODE(ROWNUM,3,vallue))
Is it possible to get the newvalues for each month (in sql only) if so, please help me
Thank you
Chand
-
Need to retrieve the names of columns with PK
Hi all
guys I need to get two columns (PK information and secondly with the column name) for the table. I see that's not so easy with Oracle ;(
I have this for now:
SELECT all_tab_cols.column_name,user_constraints.constraint_type FROM all_tab_cols, user_cons_columns, user_constraints,user_ind_columns, user_indexes WHERE all_tab_cols.column_name = user_cons_columns.column_name (+) AND all_tab_cols.table_name = user_cons_columns.table_name (+) AND user_cons_columns.constraint_name = user_constraints.constraint_name (+) AND user_constraints.constraint_type (+) = 'P' AND user_ind_columns.column_name (+) = all_tab_cols.column_name AND user_ind_columns.table_name (+) = all_tab_cols.table_name AND user_indexes.uniqueness (+) = 'UNIQUE' AND user_indexes.index_name (+) = user_ind_columns.index_name AND all_tab_cols.table_name = 'MYTABLE'
but, if KP is then take result duplicate me lines and there is not a simpler way? just need to list all columns of the table with information about the PK
SELECT acc.column_name, ac.constraint_name FROM all_constraints ac, all_cons_columns acc WHERE ac.owner =acc.owner AND ac.constraint_name=acc.constraint_name AND ac.table_name =acc.table_name AND ac.constraint_type='P' AND ac.table_name = 'MY_TABLE' UNION SELECT column_name,NULL FROM all_tab_columns WHERE table_name='MY_TABLE';
-
Hello
I'm trying to achieve the following objectives:
1. in table A, select rows based on the values in column 2. something like SELECT * FROM TABLE A WHERE (COLUMN2 = 'X' or Column2 IS NULL)
2 and these values selected, I want to update Column3 from Table A if TableA.column1 = TableB.column1, but only if there is exactly one game. If there are multiple matches, column 3 of the table article updated.
That's what I've tried so far.
UPDATE TABLE_A
SET
TABLE_A.COLUMN3 = (SELECT COLUMN3 OF TABLE_B
WHERE ((TABLE_B.COLUMN1 = TABLE_A.COLUMN1) AND ( TABLE_B.COLUMN1 IN (SELECT Column1 FROM TABLE_B GROUP BY COLUMN1 , HAVING COUNT (*) = 1)))
WHERE EXISTS (SELECT * FROM TABLE_A)
WHERE ((TABLE_A.COLUMN2 = 'X' OU TABLE_A.COLUMN2 = 'Y') AND (TABLE_A.COLUMN4 IS NULL OR TABLE_A.COLUMN4 = ' ')));
More details on my DB environment:
Version Info:
Oracle Database 11 g Enterprise Edition Release 11.2.0.4.0 - 64 bit Production
PL/SQL Release 11.2.0.4.0 - Production
Toad, but, depending on whether the query updated all lines. I would really appreciate if someone could tell me how to fix my request.
Thanks in advance.
Exists it predicate in the block of update will be set to true if there is at least one row in table_a where column2 is X or Y and column4 is null or a space. You need to correlate exists it with the outer query query (I'm guessing on column1) to get the result I think you want. However, who would update all rows in table_a who meets the criteria, there is a corresponding row in table_b, affecting Column3 lines form null not matched or not. (Again), I'm guessing that's not your intention. If you only want to update the lines in table_a which have a corresponding line in table_b and meet the other predicate, then I think you want something more like:
Update table_a
Set table_a.column3 = (select column3 of table_b
where table_b.column1 = table_a.column1 and
Table_B.Column1 in (select column1 from table_b
Group by column1, having count (*) = 1))
where ((table_a.column2 = 'X' ou))
table_a.Column2 = 'Y') and
(table_a.column4 is null or)
table_a.column4 = ' ')) and
table_a.Column1 in (select column1 from table_b
Group by column1, having count (*) = 1)
John
-
Hierarchy in a single column, with a hole more
Hello
I have the following query, which built a hierarchy:with it_dept (orga3) as
(
Select '0305' across double Union
Select "03050202" of any double union
Select "03050105" of any double union
Select "03050001" of any double union
Select "03050106" of any double union
Select "03050203" of any double union
Select "03050107" of any double union
Select "0305000101" of any double union
Select "0305000102" of any double union
Select "0305000103" of any double union
Select "0305020201" of any double union
Select "0305020202" of any double union
Select "0305020203" of any double union
Select "0305020301" of any double union
Select "0305020302" of any double union
Select "03050204" of any double union
Select "0305020401" of any double union
Select "0305020402" of any double union
Select "0305010501" of any double union
Select "0305010502" of any double union
Select "0305010601" of any double union
Select "0305010602" of any double union
Select "0305010701" of any double union
Select "0305010702" of any double union
Select "030501" of any double union
Select '030502' double
)
Select parent_org,
child_org,
level lvl
Of
(
Select parent_org null,
child_tbl.orga3 child_org
of it_dept child_tbl
where length (child_tbl.orga3) = (select min (length (orga3))
of it_dept
)
the Union / * cover the hole * /.
Select '0305' parent_org,
'030500' child_org
of the double
Union
Select parent_tbl.orga3 parent_org,
child_tbl.orga3 child_org
of it_dept parent_tbl
outer join left it_dept child_tbl
on parent_tbl.orga3 = substr (child_tbl.orga3, 1, length (parent_tbl.orga3))
and (child_tbl.orga3) length = length + 2 (parent_tbl.orga3)
)
Connect prior child_org = parent_org
Start with parent_org set to null.
1. the data is organized in such a way that they build a hierarchy. Each level of
This has the same number of digits.
2. the data of the hierarchy is on a specific data column (i.e.: orga3).
3. There's a hole in the hierarchy, which means that a member is missing (namely: the 2nd member of '030500' level).Issues related to the:
(1) is there a simpler way to achieve the same result?
(2) is it possible do not write the missing member, in order to cover the hole?
(3) is it possible do not write + 2 (as in the line "and length = length + 2 (parent_tbl.orga3) (child_tbl.orga3)") for
in terms of getting the members of next level?
Note: I'm using OracleDb 11 g v.2Thank you
SIMWhen I see a problem that really needs a better model of data, I wonder: ' how would I migrate data to a better model?
Once I wrote the SQL code to migrate the data, the SQL to meet the requirement is simple.
If you cannot migrate the code, just run the two SQL bits, one after the other.
For example, the test data:
create table it_dept(orga3) nologging as select '0305' from dual union all select '03050202' from dual union all select '03050105' from dual union all select '03050001' from dual union all select '03050106' from dual union all select '03050203' from dual union all select '03050107' from dual union all select '0305000101' from dual union all select '0305000102' from dual union all select '0305000103' from dual union all select '0305020201' from dual union all select '0305020202' from dual union all select '0305020203' from dual union all select '0305020301' from dual union all select '0305020302' from dual union all select '03050204' from dual union all select '0305020401' from dual union all select '0305020402' from dual union all select '0305010501' from dual union all select '0305010502' from dual union all select '0305010601' from dual union all select '0305010602' from dual union all select '0305010701' from dual union all select '0305010702' from dual union all select '030501' from dual union all select '030502' from dual;
To migrate the data, I have to assume that there is difference of 2 bytes between child and parent. If you introduce a difference of 1 or 3 bytes, we're all lost.
create or replace view new_it_dept as with minlen as ( select min(length(orga3)) minlen from it_dept ) , filled_hierarchy as ( select distinct substr(orga3,1,minlen+(level-1)*2) orga3, minlen from it_dept, minlen connect by orga3 = prior orga3 and prior sys_guid() is not null and length(orga3) >= minlen+(level-1)*2 ) select case when length(orga3) > minlen then substr(orga3,1,length(orga3)-2) end dad, orga3 son from filled_hierarchy;
If you create a table with that point of view, you have migrated data. If you cannot migrate, then simply use the view in your query.
select dad, son, level from new_it_dept start with dad is null connect by dad = prior son;
DAD SON LEVEL 0305 1 0305 030500 2 030500 03050001 3 03050001 0305000101 4 03050001 0305000102 4 03050001 0305000103 4 0305 030501 2 030501 03050105 3 03050105 0305010501 4 03050105 0305010502 4 030501 03050106 3 03050106 0305010601 4 03050106 0305010602 4 030501 03050107 3 03050107 0305010701 4 03050107 0305010702 4 0305 030502 2 030502 03050202 3 03050202 0305020201 4 03050202 0305020202 4 03050202 0305020203 4 030502 03050203 3 03050203 0305020301 4 03050203 0305020302 4 030502 03050204 3 03050204 0305020401 4 03050204 0305020402 4
Maybe you are looking for
-
print screen does not work with ios 10
I used to take screenshots by pressing the sleep/wake button and the home button. with ios 10.01, it no longer works. even if I get home before the sleep button sleep. even if I press them together very quickly. It does not work. I tried several time
-
Change the kind of movie crashing iTunes
Hello I've been ripping and cataloging my movies for years. I use subler to add metadata once I ripped my movie and since the last update to iTunes (12.4.009) when I want to change the genre of the film from say just action or thriller Action/Thrille
-
CP 2025 DW: CP2025 - function ceased after updates
I accidentally posted this in the wrong forum, so I re-post here (I hope this is the right place this time!). The original post is at: http://h30499.www3.hp.com/t5/Windows-7/CP2025-ceased-function-after-updates/m-p/6751297 Hello, I have a laserjet CP
-
are you offer always the free sp2 disc
Microsoft offers the free sp2 disk if so, how do one
-
Vista inquire file haqrueo.dll during initialization
Hello My wife has a strange problem with his hotebook with Vista. After you have repaired the virus detected with AVG on the flash drive, the system to ask about the missed file AppData/Roaming/haqrueo.dll Could someone help me solve this? What is th