Shouldn't be using WITH return the same results as if you would first put the results in a table?
First of all, here is my version info:
BANNER
--------------------------------------------------------------------------------
Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE Production 11.1.0.7.0
AMT for HP - UX: 11.1.0.7.0 - Production Version
NLSRTL Version 11.1.0.7.0 - Production
I just re-read the documentation of the subquery factoring clause of select again and I saw no restriction that applies.
Can someone help me understand why I get different results? I would like to be able to use the statement that creates spades3, but for some reason it does not work. However, when I break up and store the last subquery TMP in a table (MAT1), I am able to get the expected results in MAT2.
Sorry if the example seems a bit esoteric. I tried to put something together to help illustrate another problem, so it was more convenient to use the same instructions to illustrate this problem.
drop table mat1; create table mat1 as with skus as ( select level as sku_id from dual connect by level <= 1000 ), tran_dates as ( select to_date('20130731', 'yyyymmdd') + level as tran_date from dual connect by level <= 31 ), sku_dates as ( select s.sku_id, t.tran_date, case when dbms_random.value * 5 < 4 then 0 else 1 end as has_changes, round(dbms_random.value * 10000, 2) as unit_cost from skus s inner join tran_dates t on 1 = 1 ) select d.sku_id, d.tran_date, d.unit_cost from sku_dates d where d.has_changes = 1 ; drop table mat2; create table mat2 as select m.sku_id, m.tran_date, m.unit_cost, min(m.tran_date) over (partition by m.sku_id order by m.tran_date rows between 1 following and 1 following) as next_tran_date from mat1 m ; drop table mat3; create table mat3 as with skus as ( select level as sku_id from dual connect by level <= 1000 ), tran_dates as ( select to_date('20130731', 'yyyymmdd') + level as tran_date from dual connect by level <= 31 ), sku_dates as ( select s.sku_id, t.tran_date, case when dbms_random.value * 5 < 4 then 0 else 1 end as has_changes, round(dbms_random.value * 10000, 2) as unit_cost from skus s inner join tran_dates t on 1 = 1 ), tmp as ( select d.sku_id, d.tran_date, d.unit_cost from sku_dates d where d.has_changes = 1 ) select m.sku_id, m.tran_date, m.unit_cost, min(m.tran_date) over (partition by m.sku_id order by m.tran_date rows between 1 following and 1 following) as next_tran_date from tmp m ; select count(*) from mat2; select count(*) from mat3; from tmp m ;
select count(*) from mat2; select count(*) from mat3;
Select count (*) from mat2;
COUNT (*)
----------
31000
Executed in 0,046 seconds
Select count (*) in spades3;
COUNT (*)
----------
0
Executed by 0,031 seconds
Hello
Khaled says:
The problem is with
-case when dbms_random.value * 5<>
You can change this
dbms_random. Value (1,100) * 5<>
and test
I don't know that I agree 100% with your police department, work there.
dbms_random. Value, no arguments, returns a random number between 0 (inclusive) and 1 (exclusive), so
dbms_random. Value * 5< 4 ="" will="" be="" true="" about="" 80%="" of="" the="">
dbms_randon. Value (1, 100) returns a random number between 1 (included) and 100 (exclusive), so
dbms_random. Value (1, 100) * 5< 4="" will="" be="" true="" exactly="" 0%="" of="" the="" time,="" which="" is="" not="" what="" op="" wants="" at="">
The problem here apparently revolves around the optimizer not really call dbms_random over and over again in sku_dates of the subquery. Add ROWNUM in the subquery seems to force Oracle to assess dbms_random.value immediately. I don't really understand myself, but adding 1 element in the SELECT of the sku_dates subquery clause could solve the problem:
create table spades3 as
with references like)
Select the level as sku_id
of the double
connect by level<=>=>
),
tran_dates like)
Select the level + to_date ('20130731', 'YYYYMMDD') as tran_date
of the double
connect by level<=>=>
),
sku_dates like)
Select s.sku_id,
t.tran_date,
-case when dbms_random.value * 5<>
then 0
1 other
end as has_changes,
Round (dbms_random.value * 10000, 2) as unit_cost
ROWNUM AS r-<=== new="" column="" added="" here="" new="" column="" added="">===>
s SKUs
inner join tran_dates t
1 = 1
),
tmp as)
Select d.sku_id,
d.tran_date,
d.unit_cost
of sku_dates d
where d.has_changes = 1
)
Select m.sku_id,
m.tran_date,
m.unit_cost,
min (m.tran_date) over (partition by order of m.sku_id by m.tran_date rows between 1 next and 1 suite) as next_tran_date
of tmp m
;
You do not have to refer to this column anywhere; just having him in the subquery is enough.
If someone can't understand why, I know it.
Tags: Database
Similar Questions
-
during the partition: how to use to return the max of two columns
Each unique id, I want to select the col2 value in the folder with the most recent date.
When the lines with the same IDS have the same dates, I select the max value of col2.
I want a line for each ID, but I get two rows for ID 3333333.
with the data as
(
Select 1111111 as id, 'a' as col2, to_date('01-JAN-09','dd-mon-yyyy') like double union all the_date
Select 2222222 as id, 'b' as col2, to_date('02-JAN-09','dd-mon-yyyy') like double union all the_date
Select 2222222 as id, 'c' as col2, to_date('03-JAN-09','dd-mon-yyyy') like double union all the_date
Select 2222222 as id, would be "like col2, to_date('04-JAN-09','dd-mon-yyyy') as the_date of all the double union"
Select 3333333 as id, 'e' as col2, to_date('05-JAN-09','dd-mon-yyyy') like double union all the_date
Select 3333333 as id, 'f' as col2, to_date('05-JAN-09','dd-mon-yyyy') like double the_date
)
SELECT id, col2, the_date
Of
(
SELECT id, the_date, max (the_date) or col2 in (score by id) as max_the_date, max (col2) over (partition of col2) as max_col2
from the data
)
where the_date = max_the_date and col2 = order by id max_col2
Expecting this:
COL2 ID THE_DATE
1111111 a 01/01/09
2222222 d 04/01/09
3333333 f 05/01/09
but I get 2 rows for ID 3333333
Any suggestions?Use row_number(), not the max() to compare.
with data as ( select 1111111 as id, 'a' as col2, to_date('01-JAN-09','dd-mon-yyyy') as the_date from dual union all select 2222222 as id, 'b' as col2, to_date('02-JAN-09','dd-mon-yyyy') as the_date from dual union all select 2222222 as id, 'c' as col2, to_date('03-JAN-09','dd-mon-yyyy') as the_date from dual union all select 2222222 as id, 'd' as col2, to_date('04-JAN-09','dd-mon-yyyy') as the_date from dual union all select 3333333 as id, 'e' as col2, to_date('05-JAN-09','dd-mon-yyyy') as the_date from dual union all select 3333333 as id, 'f' as col2, to_date('05-JAN-09','dd-mon-yyyy') as the_date from dual ) select id, col2, the_date from (select id, the_date, col2, row_number() over (partition by id order by the_date desc, col2 desc) r from data) where r = 1; ID COL2 THE_DATE ---------------------- ---- ------------------------- 1111111 a 01-JAN-09 2222222 d 04-JAN-09 3333333 f 05-JAN-09 3 rows selected
Published by: tk-7381344 on March 5, 2009 11:46
-
Adding timestamp with all the elements of a table 1 d
Hello
I want to add a stamp in real time with all the elements of a 1 d array before writing on a worksheet.
kindly guide me how to do this.
Best regards
RASHID
Hi rachid,.
Whence this table? Is a device for the acquisition of data AND measurement data?
If yes you can just change the type of waveform data, where a timestamp is included.
However, you can also create a waveform on your table 1 d using construction wavefrom, as here:
Christian
-
The question is over the top
Hi Michel,.
Perhaps, this happens when the author or sender of the file applies the security settings on the pdf file so that other users would not be able to comment on the file.
You have created the file? Please check if there are security restrictions on the file under properties of the document.
Kind regards
Rahul -
Problem with trunacating the partitions of a table.
Hi all
I have a table partitioned, called temp1_list_cmpgn_hist_dtl, and it is partitioned by month (campaign_start_date).
I tried, queries
TRUNCATE TABLE temp1_list_cmpgn_hist_dtl PARTITION t_list_cmpgn_201006
TRUNCATE TABLE temp1_list_cmpgn_hist_dtl PARTITION t_list_cmpgn_201006 REUSE STORAGE
but it throws me the following error message:
SQL error: ORA-03291: Invalid truncate option - missing keyword STORAGE
03291 00000 - "invalid truncate option - missing keyword STORAGE"
* Cause: Keyword STORAGE planned
* Action: Specify DROP STORAGE or reuse STORAGE
Also, I'll try to find the nom_partition for the 'temp1_list_cmpgn_hist_dtl' table, but it shows not all partitions, although there are partitions.
I tried the query,
SELECT Nom_partition from user_tab_partitions WHERE table_name = 'temp1_list_cmpgn_hist_dtl '.
THX,
Rod.You cannot truncate individual partitions of a table. The closest you could come would be to do a swap partition with an empty table created to match your partition.
Also, I'll try to find the nom_partition for the 'temp1_list_cmpgn_hist_dtl' table, but it shows not all partitions, although there are partitions.
I tried the query,
SELECT Nom_partition from user_tab_partitions WHERE table_name = 'temp1_list_cmpgn_hist_dtl '.All the names of objects in the Oracle database, by default, are stored in uppercase letters, so make sure the upper case of the table name.
John
-
Can do us a query to get the same results of 3 tables
CREATE TABLE TABLE1 (NODEID VARCHAR2 (4));
CREATE TABLE TABLE2 (NODEID VARCHAR2 (4));
CREATE TABLE TABLE3 (NODEID VARCHAR2 (4));
INSERT INTO TABLE1 VALUE('1004');
INSERT INTO TABLE1 VALUE('1004');
INSERT INTO TABLE1 VALUE('1002');
INSERT INTO TABLE1 VALUE('1002');
INSERT INTO TABLE1 VALUE('1001');
INSERT INTO TABLE1 VALUE('1001');
INSERT INTO TABLE1 VALUE('1006');
INSERT INTO TABLE1 VALUE('1006');
INSERT INTO TABLE1 VALUE('1005');
INSERT INTO TABLE1 VALUE('1005');
INSERT INTO TABLE2 VALUE('1004');
INSERT INTO TABLE2 VALUE('1004');
INSERT INTO TABLE2 VALUE('1004');
INSERT INTO TABLE2 VALUE('1002');
INSERT INTO TABLE2 VALUE('1002');
INSERT INTO TABLE2 VALUE('1002');
INSERT INTO TABLE2 VALUE('1002');
INSERT INTO TABLE 3 VALUE('1001');
INSERT INTO TABLE 3 VALUE('1001');
INSERT INTO TABLE 3 VALUE('1006');
INSERT INTO TABLE 3 VALUE('1006');
INSERT INTO TABLE 3 VALUE('1005');
INSERT INTO TABLE 3 VALUE('1005');
INSERT INTO TABLE 3 VALUE('1004');
INSERT INTO TABLE 3 VALUE('1004');
INSERT INTO TABLE 3 VALUE('1004');
INSERT INTO TABLE 3 VALUE('1002');
INSERT INTO TABLE 3 VALUE('1002');
INSERT INTO TABLE 3 VALUE('1002');
INSERT INTO TABLE 3 VALUE('1002');
SELECT count (*), count (distinct nodeid)
of table1, table2, table3
where table1.nodeid = table2.nodeid and table1.nodeid = table3.nodeid;
SELECT count (*), count (distinct nodeid)
FROM table1, table3
where table1.nodeid = table2.nodeid;
SELECT count (*), count (distinct nodeid)
from table2, table3
where table2.nodeid = table3.nodeid;SQL> SELECT MAX (CASE WHEN row_ind = 1 THEN ct END) ct_1, 2 MAX (CASE WHEN row_ind = 1 THEN distinct_ct END) distinct_ct_1, 3 MAX (CASE WHEN row_ind = 2 THEN ct END) ct_2, 4 MAX (CASE WHEN row_ind = 2 THEN distinct_ct END) distinct_ct_2, 5 MAX (CASE WHEN row_ind = 3 THEN ct END) ct_3, 6 MAX (CASE WHEN row_ind = 3 THEN distinct_ct END) distinct_ct_3 7 FROM (SELECT 1 AS row_ind, 8 COUNT (*) ct, 9 COUNT (DISTINCT table1.nodeid) distinct_ct 10 FROM table1, table2, table3 11 WHERE table1.nodeid = table2.nodeid 12 AND table1.nodeid = table3.nodeid 13 UNION ALL 14 SELECT 2 AS row_ind, COUNT (*), COUNT (DISTINCT table1.nodeid) 15 FROM table1, table3 16 WHERE table1.nodeid = table3.nodeid 17 UNION ALL 18 SELECT 3 AS row_ind, COUNT (*), COUNT (DISTINCT table2.nodeid) 19 FROM table2, table3 20 WHERE table2.nodeid = table3.nodeid) 21 / CT_1 DISTINCT_CT_1 CT_2 DISTINCT_CT_2 CT_3 DISTINCT_CT_3 ---------- ------------- ---------- ------------- ---------- ------------- 50 2 26 5 25 2
There may be an easier way...
-
The query sql without prescription by will return same result on several tracks?
Hello
I have a sql without a prescription and I limit the number of rows to 100 max per rownum < 100. Now the question is, if the data set on which this sql is running, does not change, the sql returns the same result the performance of several?
For example, there are 150 lines and the sql returns 100 rows because of rownum < 100. Now running the same sql several times, I have the same set of 100 lines? or it could be 150? On the basis of these the kind of database engine and return data when no order by clause are provided?
Thank you for your time.
-HozyHi, Hozy,
Hozy says:
HelloI have a sql without a prescription and I limit the number of rows to 100 max per rownum< 100.="" now="" the="" question="" is,="" if="" the="" data="" set="" on="" which="" this="" sql="" runs,="" does="" not="" change,="" will="" the="" sql="" return="" the="" same="" result="" set="" on="" multiple="">
N ° if there is no ORDER BY clause, then there is no guarantee that the order will remain the same. If the table is small, the output will probably be the same thing, but you can't count on it.
I guess that you do not have a CONNECT BY query. CONNECT BY queries without ORDER BY clause or brothers and SŒURS of ORDER BY, the output is partially ordered.For example, there are 150 lines and the sql returns 100 rows due to rownum< 100.="" now="" on="" executing="" the="" same="" sql="" multiple="" times,="" will="" i="" get="" the="" same="" set="" of="" 100="" rows?="" or="" it="" could="" be="" any="" of="" the="" 150?="" on="" what="" bases="" these="" the="" database="" engine="" sort="" and="" return="" data="" when="" no="" order="" by="" clause="" is="">
No, you necessarily will not get the same 100 lines each time. ROWNUM reflects the order in which the establishment has recovered the lines.
Say you run the query at 11:00. Maybe do you a full table scan to obtain the data on the drive, and the order of the lines is determined by how it data happens to be on the disk. As the data is read from the disk, it is cached in memory.
Say you run the same exact query at 12:00, without changing the table. Instead of retrieve all data from the disk, Oracle will try to use the blocks that are cached in memory, which is not necessarily the way the blocks are stored on the disk. If some of the older blocks 11:00 to 12:00 (otherwise said, some, but not all, blocks are more in memory because memory was required for other purposes), then the items picked up at 11:00 can be recovered first at 12:00 and the lines that I have high ROWNUMs at 11:00 can get low ROWNUMs at 12:00. (See Matthew 7:30.)Again, you would never notice it on a small table. You can run this query
SELECT ename FROM scott.emp WHERE ROWNUM < 10;
a thousand times and get the same results every time. You will get the same results the 1001eme time? Probably, but not necessarily.
If you want the output to be in a particular order, to use an ORDER BY clause in the main query.
If you want ROWNUM to reflect a particular order, use a subquery with an ORDER BY clause and ROWNUM reference in the main query. -
video cards can be used with a HP Pavilion HPE - 180 t office.
Using a videocard ATI (AMD) radeon 4850. It went wrong, and so I would like to know what other video cards can be used with a HP Pavilion HPE-180 t office.
The Ribbon for the video card cable connector can be used with all video cards?
Thank you
Hi Mike,.
I suggest you post the question on the link below. The link given below is supported for HP Forum link. As you use HP, they can help you better than us on the compatibility of the video card with their computer.
http://h30434.www3.HP.com/T5/laptop-and-notebook-computers/CT-p/notebook
Feel free to write us if you have any other issues related to Windows.
-
Can what kind of command I use to return the path of the after effects project?
Also, is there a way to call a python script from the script or even embed a python function in the script itself? We have some libraries for management of files we use to nuke and some of the features that I'll need to recreate in extendscript, but if it was maybe a way to call these functions and return a value, it could save me some time not to reinvent the wheel.
The full path would be:
App.Project.file.Path + "/" + app.project.file.name
(assuming that the project has been saved).
I'm not sure of the python stuff, but I suspect that you can not do. Please report if you find otherwise.
Dan
-
Get all the rows of a table control
Hi all
I have a table with a column control. What function can I use to extract all lines? I have to go row by row and read each line or is it possible to do in a function?
Thank you
Kanu
Assuming that Garay in the column have all of the same data type, you can retrieve the entire column with a single statement:
GetTableCellRangeVals (Panel, control, VAL_TABLE_COLUMN_RANGE (1), array, VAL_COLUMN_MAJOR);
The array passed must be large enough to recover all data. Alternatively, you can replace the VAL_TABLE_COLUMN_RANGE with the appropriate statement of MakeRect macro. In the event that your table was built of dynamically, you can get the naked, imber of lines using GetNumTableRows and size your table accordingly.
The above macro is defined in userint.h as well as some other useful macros that can be used to access the data in a table.
There are a few precautions to be taken in the case of string values or a certain type of cell (ring, combo box, button...) that are described in the hell of the function.
-
CP5: Why you would choose to use branching?
For those of you who use branching, can help me understand why you would use branching, what is the advantage? Couldn't do you the same thing with a few buttons and move to slide actions?
Thank you.
Hello
I am admittedly a bit confused by the question. Ask why, you would use an offshoot is not unlike asking why you would use a vehicle to drive from New York to Los Angeles. The ramification is only action.
So with this in mind it occurs to me you're talking maybe to the Panel view connection? If so, it's just another way to consider your project if you can see sort of a "road map" If you want to, how the path goes through the slide to the slide.
Personally, I never use the tools included in the Panel branch actually configure the branching. But that's just me.
See you soon... Rick
Useful and practical links
Begin to learn Captivate 5 times now! $29.95
Captivate wish form/Bug report form
-
I have a Windows 7 key I used with Parallels (on my Mac). I was unable to uninstall Parallels, and now I want to use my key Windows with Boot Camp instead. How can I turn off the key to the prior use (same computer)? Is this possible?
Unfortunately, I am not able to return to Parallels. (I upgraded my Mac o/s to an incompatible version with the version of Parallels, I had installed).
Thanks for the suggestion, if!
I'll try MS service the customer the morning... wish me luck!
Just proceed to install Windows 7 in Boot Camp and reactivate by telephone by following the instructions.
-
I am in India, I was using Iphone 6, 16GB, for the last 18 months, bought in Australia, progressively, the touch screen not responding. Then the problem started to happen frequently. I said, all ideas update, (9.3.2) reset, restore, etc., etc., nothing helped, finally the Apple so-called service center has confirmed that it is a hardware problem, is not repairable and advised me to return the phone and scrap it or to pay nearly 60% of the phone cost to get another phone as replacement. (It might be a refurbished phone). As I see a lot of complaints in the blogs on the problems of the iphone 6, Apple has not taken any measure to solve my problem and trying to make more money on behalf of replacement... Now I'm stuck with such a pricey gadget... should I buy new Iphone?
Sorry, but an iPhone can be repaired by Apple or a Service provider authorized Apple in the country of purchase. If you think of buying a new device, buy it in the country where you will use it will save you a lot of trouble if you need service.
And, according to usage, a 16 GB model might not have enough free space left to work properly, which can also cause the phone to lag and unresponsive at times.
-
Adobe flash is updated, but firefox says its not installed and install. Flash does not work in sites using Firefox, but the same read in IE or Google chrome sites work with flash. I use a dell high spec, less than a year using windows 7 Home premium processor Intel (r) Pentium (r) CPU P6100 @ 2.00 GHz, 1999 Mhz, 2 Lossnay, 2 logic and McAfee Firewall and AV processors
Thank you so much for pointing me in the right direction... Unfortunately, the link does not work but I bypassed using a part of the link, I did a search on google and found the plugin here. Adobe.com/Get/flashplayer/Current/install_flash_player.exe
Thank you so much,.
Johnny 777777
-
Function returning the tree used with the object type
Hi guys!
I'm fighting for some time now of a function that should return the tree structure of the employees. Let me clarify...
I have a table say Manager and employees (two columns for an example)
MANAGER_ID
EMPLOYEE_ID
Example:
MAN_ID - 1; EMPLOYE_ID - 2;
MAN_ID - 2; EMPLOYE_ID - 3;
MAN_ID - 2; EMPLOYE_ID - 4;
MAN_ID - 4; EMPLOYE_ID - 5
The purpose of my function is back for a specified MAN_ID everyone in the tree...
Example:
RETURN_TREE (1) return {2,3,4,5};
RETURN_TREE (2) returns {3,4,5};
RETURN_TREE (4) returns {5};
How to get there?
With respect,
PsmakRAnd use BULK COLLECT or the COLLECT function to build the collection:
create type emp_table as table of number(6); /
DECLARE v_emp_list emp_table; BEGIN select cast(collect(employee_id) as emp_table) into v_emp_list from employees connect by prior employee_id = manager_id start with manager_id = :p_man_id -- or /* select employee_id bulk collect into v_emp_list from employees connect by prior employee_id = manager_id start with manager_id = :p_man_id */ END; /
Maybe you are looking for
-
PSP10 satellite driver for FX 5600 GeforceGo?
Hello! I got this noteboook mentioned in the topic, and my question is: where to find new drivers for the GFX card? Toshiba drivers are old (they are lying from 2004, but all the driver files in this archive have been modified in 2003...) that even h
-
How to get the path of the 64-bit application?
I worked with the builtin function to get the system directory on a 64-bit computer that is running Windows 7 and noticed that the selection of path of Application file always returns the path to the directory for 32-bit programs (for example, c:\Pro
-
It seems that every time that my backflip Gets the lower pot as I open the phone quickly or type it on my desk that it restarts. does anyone else have this problem? or is it just a bad phone I need to at & t to switch out. I'm just skeptical about th
-
KB972270 security update failed to install
KB972270-security update will not be installed. I checked the services.msi for windows install, automatic updates, intelligent transfer background and services of encryption to make sure that they are started and automatic mode (by microsoft chat); I
-
My mother bought a new laptop today, a HP G6 1302eo, but there was no CD of windows with it. Why? I need. I wanted to make a partition and arrived to make the dynamic disk and want to return that. Why the hell do you want to sell a PC without the BON