Query to find data conneting that intersect each other.
Hello
I have a table like road_point_ids (script is below). Basically, this table have road_id with its start and its end point.
I'm looking for a query that actually will connect each ID path beginning or end points.
create the table road_point_ids
(
road_id number (10),
start_point number (10),
Number of end_point (10)
);
insert into road_point_ids
values (1001, 10, 20);
insert into road_point_ids
values (1002, 20, 30);
insert into road_point_ids
values (1003, 30, 40);
insert into road_point_ids
values (1004, 40, 50);
insert into road_point_ids
values (1005, 50, 10);
insert into road_point_ids
values (1006, 70, 75);
insert into road_point_ids
values (1007, 30, 50);
insert into road_point_ids
values (1008, 10, 40);
insert into road_point_ids
values (1009, 80, 70);
insert into road_point_ids
values (1010, 90, 95);
insert into road_point_ids
values (1011, 50, 60);
commit;
SQL > select * from road_point_ids by 2;
ROAD_ID START_POINT END_POINT
----------- ----------- -----------
1001 10 20
1008 10 40
1002 20 30
1007 30 50
1003 30 40
1004 40 50
1011 50 60
1005 50 10
1006 70 75
1009 80 70
1010 90 95
11 selected lines
In the example above only seven road_ids intersect at TWO points corresponding to start or end point.
Output desired must be as...
ROAD_ID | START_POINT | END_POINT | |
1001 | 10 | 20 | |
1002 | 20 | 30 | |
1003 | 30 | 40 | |
1004 | 40 | 50 | |
1005 | 50 | 10 | |
1007 | 30 | 50 | |
1008 | 10 | 40 |
7 selected lines
I tried to use a lot of operator AND with the OR operator but sent to an incorrect result. Could someone provide me please help.
Thanks in advance
Saaz
Hi, Saaz,
How is this problem differs from your original problem?
If it's just that the data is now contained in 2 tables (a few lines in a table, a few lines in the other) instead of a table, you can change my original solution by using a UNION to combine the two tables into one:
WITH road_point_ids AS
(
SELECT road_id, start_point, end_point OF road_point_ids_1 UNION ALL
SELECT road_id, start_point, end_point FROM road_point_ids_2
)
SELECT DISTINCT road_id, start_point, end_point
OF road_point_ids
WHERE CONNECT_BY_ISCYCLE = 1
CONNECT BY NOCYCLE start_point = PRIOR end_point
;
The WITH clause is new; the main request is that I posted earlier.
Tags: Database
Similar Questions
-
Query to find data of each month
Hello
I have 2 tables.
(1) Order_tb
Name Null? Type
----------------------------------------- -------- ----------------------------
ORDERID NOT NULL NUMBER
NUMBER OF CUSTOMERID
ORDERDATE DATE
(2) Order_d
Name Null? Type
----------------------------------------- -------- ----------------------------
ORDERID NUMBER
PRODUCTID NOT NULL NUMBER
PRODUCTNAME VARCHAR2 (20)
NUMBER OF SELLINGPRICE
I need to find the total find the selling price for each month of the year 2012 (orderdate) total.
I tried to use join, but I couldn't take the 2012 in particular data. Please help me on this issue.
Thank you
Published by: RSD on February 28, 2013 09:18Hello
RSD wrote:
I tried to use join, but I couldn't take the 2012 in particular data. Please help me on this issue.The WHERE clause below, is what limits the results for 2012.
SELECT TRUNC (t.orderdate, 'MONTH') AS month , SUM (d.sellingprice) AS total_sellingprice FROM order_tb t JOIN order_d d ON d.orderid = t.orderid WHERE t.orderdate >= DATE '2012-01-01' AND t.orderdate < DATE '2013-01-01' GROUP BY TRUNC (t.orderdate, 'MONTH') ORDER BY TRUNC (t.orderdate, 'MONTH') ;
I hope that answers your question.
If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
Simplify the problem. For example, pretend you're only interested in the first 3 or 4 months of 2012; We will find a solution tht can easily be adapted for 12 (or any other number) of motnhs.
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 {message identifier: = 9360002} -
query to find bad queries that are taking place
I write a job that takes place each a work hour.the will execute the query, the query will select identifiers of bad queries sql which is need for queries that have long been and always in running currently.we will run this work every time some sort of query has bad queries that perform queries currently.the o/p will be inserted into a table.i query to choose bad queries that is currently running
something like that? (Instead of setting long-term work I would simply sort by time)
SELECT sql_id
executions
elapsed_time
TO_CHAR (buffer_gets, '999G999G999G999G999') buffer_gets
, "percent overall.
TO_CHAR (buffer_ex, '999G999G999G999') buffer_ex
TO_CHAR (rows_ex, '999G999G999G999') rows_ex
TO_CHAR (buffer_gets_row, '999G999G999G999') buffer_gets_row
sql_text
FROM (SELECT sql_id
executions
elapsed_time
sql_text
buffer_gets
, ROUND ((buffer_gets) ratio_to_report () * 100) '% overall.
, buffer_gets / buffer_ex of executions
, rows_processed / rows_ex of executions
, buffer_gets / DECODE (rows_processed, 0, 1, NULL, 1, rows_processed) buffer_gets_row
V $ sql
WHERE executions > 0
AND buffer_gets > 0
Sql_id AND to (select sql_id in session $ v where status = 'ACTIVE'))
WHERE the "Total %" > = 5
OR buffer_ex > 1000
OR buffer_gets_row > 8
ORDER BY DESC elapsed_time;
(I guess you can't use v$ sql_monitor, otherwise the answer.)
-
Need to query to find stored procedures that takes great execution time
Hi all
I use the oracle version below:
Oracle Database 11 g Release 11.2.0.3.0 - 64 bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE Production 11.2.0.3.0
AMT for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
is it possible to find the name of stored procedure that take too long to run, I need those optimized all SPs.
Is there a query as top queries that are used to find queries albums that have great time for execution...
or y at - it another way to find the names of MS. I try with AWR report but showing only used the names of MS.
Thank you
No, it not there no such request as far as I know.
or y at - it another way to find the names of MS.
Just listen to complaints from the user...
-
Need to create a report across data center that summarizes each cluster
I created a few reports of various kinds, layers to multiple views and used filters for will only display me specific data. However, I don't find a way to summarize or failure, a report by a resource of the child.
To be precise, I'm looking to get information about the data at the data center or vCenter level stores, grouped by cluster. Currently, I can obviously pull 53 different reports and getting these data on a per-cluster basis, but I want to be able to do is have a summary of each cluster in a single report. Currently, the report is perfectly functional vcenter down to a host, but it displays each individual data store and the summary only I can give is all grouped together, and is not an indication that data warehouses are in clusters.
Is there a way to do this?
I would like that the report looks simply:
Data Center
Group 1
Data warehouses
Summary
Group 2
Data warehouses
Summary
and so on...
I am currently on vROps 6.1.
You can do things with the summary views and the bubble to the top a few statistics by using Supermetrics in some cases, but the possibilities for nesting are today a bit limited in terms of nesting of data visually in views. Of data are what kind of data from the warehouses you trying to show?
-
Problem with query to find data offset
Hello PL/SQL gurus and Experts.
I am not able to extract the data with the following table structure-
I want to extract the data in the following format-drop table T2; create table T2(Stream, Trade, Fees) as select 'MECHNICAL', 'Primary', '5534500' from dual union all select 'ELECTRICAL', 'Secondary', '5285500' from DUAL union all select 'MECHNICAL', 'Secondary', '2364535' from dual union all select 'ELECTRICAL', 'Primary', '1734540' from DUAL union all select 'MBE', 'Secondary', '3424500' from dual union all select 'ELECTRONICS', 'Primary', '5004567' from DUAL union all select 'ELECTRONICS', 'Secondary', '4543200' from DUAL union all select 'COMPUTERS', 'Secondary', '5534500' from DUAL union all select 'CIVIL', 'Primary', '2345500' from DUAL union all select 'CIVIL', 'Secondary', '4456500' from DUAL union all select 'COMPUTERS', 'Primary', '9542500' from DUAL;
Now if I use the following query-Stream Trade Fees MECHNICAL Primary 5534500 Secondary 2364535 ELECTRICAL Primary 1734540 Secondary 5285500 ELECTRONICS Primary 5004567 Secondary 4543200 CIVIL Primary 2345500 Secondary 4456500 MBE Primary Secondary 3424500 Total 34693342
SELECT CASE WHEN LAG(Stream||Trade) OVER (ORDER BY Stream, Trade, Fees) = Stream||Trade THEN NULL ELSE Stream END Stream , CASE WHEN LAG(Stream||Trade) OVER (ORDER BY Stream, Trade, Fees) = Stream||Trade THEN NULL ELSE Trade END Trade , CASE WHEN LAG(Fees) OVER (partition by Stream||Trade ORDER BY Stream, Trade, Fees) = Fees THEN NULL ELSE Fees END Fees FROM ( select distinct Stream, Trade, Fees from T2 ORDER BY Stream, Trade, Fees);
Kindly help me...SELECT NVL2(LAG(Trade) OVER (PARTITION BY Stream, Trade ORDER BY Stream, Trade, Fees),Null,Trade) Trade, NVL2(LAG(Stream) OVER (PARTITION BY Stream, Trade ORDER BY Stream, Trade, Fees),Null,Stream) Stream, Fees from (select distinct Stream, Trade, Fees from T2)
Thank you all for your time and effort in advance.use the below. There would be better ways to achieve, I find it easier.
with filtered as ( select case row_number() over(partition by stream order by trade) when 1 then stream else null end stream2,trade,fees from t2 order by stream,trade ) select stream2 stream, trade, to_number(fees) from filtered union all select 'Total', null, sum(fees) from t2; STREAM TRADE TO_NUMBER(FEES) ----------- --------- ---------------------- CIVIL Primary 2345500 Secondary 4456500 COMPUTERS Primary 9542500 Secondary 5534500 ELECTRICAL Primary 1734540 Secondary 5285500 ELECTRONICS Primary 5004567 Secondary 4543200 MBE Secondary 3424500 MECHNICAL Primary 5534500 Secondary 2364535 Total 49770342
I hope that it meets your needs. If this isn't the case, then please don't forget to provide the expected results, because we have to guess, if you still want to exit expected Original or there is a diversion in it.
-
need help with query can find data back please help.
Hi guys I have a table such as
and I have a data as suchCREATE TABLE "FGL" ( "FGL_GRNT_CODE" VARCHAR2(60), "FGL_FUND_CODE" VARCHAR2(60), "FGL_ACCT_CODE" VARCHAR2(60), "FGL_ORGN_CODE" VARCHAR2(60), "FGL_PROG_CODE" VARCHAR2(60), "FGL_GRNT_YEAR" VARCHAR2(60), "FGL_PERIOD" VARCHAR2(60), "FGL_BUDGET" VARCHAR2(60) )
I need bascially to get the total of the budget column. However this is not as simple as it sounds good (at least not for the me.) totals carried forward to the new period. you will notice that you have a period column. Basically, what im is thatInsert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','1','100'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','2','100'); Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7470','4730','02','10','2','200');
fgl_grant_year 10 1 period = account 7600 its $100 and $100 for the period 2, you see $ 100 more, it wants to not be added to this is the door on the balance. that is $100.
So im trying to write a query that basically does the following.
IM considering a period for the sake of this example let period 1 I get anything else. I find that the greates contributes dumpster year the amount for the period 14 (which corresponds to the total of the previous year) and add it to the amount of the current year. in this case period 1 grnt_year 11
the expected result is therefore $700
do not forget that I am not given a just a period of the year.240055 240055 7240 4730 02 10 14 200 240055 240055 7600 4730 02 10 14 100 240055 240055 7600 4730 02 11 1 400
any help you guys can give would be immensely appreciated. I tried to get this to work for more than 3 days now.
Finally broke down and put together this post
Published by: mlov83 on Sep 14, 2011 20:48Hello
Thanks for posting the CREATE TABLE and INSERT statemnts; It is very useful.
I'm not sure that understand your needs.
The correct output will be just one line:TOTAL_BUDGET ------------ 700
or will it be 3 ranks that you posted? I guess you want just line after line.
Do you mean that you are given a period (for example, 1).
First you have to find the largest gfl_grnt_year which is related to this period (in this case, 11).
Then you need to add fgl_budget lines that have to be
(1) the specific period and the largest fgl_grnt_year, or
(2) perriod = 14 and the previous fgl_grnt_year (in this case, 10).
Is this fair?If so, here's a way to do it:
WITH got_greatest_year AS ( SELECT fgl.* -- or whatever columns are needed , MAX ( CASE WHEN fgl_period = :given_period THEN fgl_grnt_year END ) OVER () AS greatest_year FROM fgl ) SELECT SUM (fgl_budget) AS total_budget -- or SELECT * FROM got_greatest_year WHERE ( fgl_grnt_year = greatest_year AND fgl_period = :given_period ) OR ( fgl_grnt_year = greatest_year - 1 AND fgl_period = 14 ) ;
If you want the 3 lines you have posted, then change the main SELECT clause to ' SELECT * ' (or, instead of *, youcan the columns you want to see the list).
-
Query to find data on holidays
Hi, I have a table for special leave, which looks like this:
PROFILE_DAY VAR_DATE REGULAR_HOLIDAY 01/01/2013 H_WEEK_THURSDAY 28/03/2013 H_WEEK_FRIDAY 29/03/2013 REGULAR_HOLIDAY 24/12/2013 REGULAR_HOLIDAY 25/12/2013 REGULAR_HOLIDAY 31/12/2013 And another table (LOAD_PROFILE_TEST) that contains the values of (TIME_EQ) 0-24 LOAD_PROF1 intervals 0.25 for (PROFILE_DAY) MONDAY to SUNDAY including REGULAR_HOLIDAY, H_WEEK_THURSDAY and H_WEEK_FRIDAY. Overall, this table contains 970 records (97 separate 0-24 with interval of 0.25 per PROFILE_DAY, with 10 PROFILE_DAY).
TIME_EQ PROFILE_DAY LOAD_PROF1 LOAD_PROF2 0 REGULAR_HOLIDAY 11.47 0.25 REGULAR_HOLIDAY 11.27 0.5 REGULAR_HOLIDAY 11.3 0.75 REGULAR_HOLIDAY 11.08 0 MONDAY 11.27 0.25 MONDAY 11.33 0.5 MONDAY 11.18 Now I have this request to update the value of LOAD_PROF2 in the table every time that the V_DATE_OUT and V_DATE_IN parameters is entered:
UPDATE LOAD_PROFILE_TEST
SET LOAD_PROF2 = LOAD_PROF1 +: LOAD_DIFF
WHERE UPPER (PROFILE_DAY) IN (select UPPER (to_char (: V_DATE_OUT + (level 1), "fmDAY")))
of the double
connect by level < =: V_DATE_IN -: + 1 V_DATE_OUT
);
where: LOAD_DIFF is some predetermined value.
This query works fine if I'm trying to update regular days from MONDAY to SUNDAY. What I would do is to determine if the two dates of setting, V_DATE_OUT & V_DATE_IN would fall under none of the holidays on the first table LOAD_PROFILE_TEST, and then update the lines only. For example, V_DATE_OUT = 12/02/2013, Monday and V_DATE_IN = 06/12/2013, Friday. The query above would update the values of the LOAD_PROF2 for PROFILE_DAY - MONDAY to FRIDAY, corresponding to the dates of 02/12/2013 and on 06/12/2013. If, however, V_DATE_OUT = 23/12/2013, Monday and V_DATE_IN = 27/12/2013, Friday, it should update the lines corresponding to PROFILE_DAY - MONDAY 23/12/2013, THURSDAY for 26/12/2013, FRIDAY for 12 27, 2013, and REGULAR_HOLIDAY for the dates of 12 24, 2013 and 25/12/2013 since these two appear in the first table (table of holidays). This scenario works the same way when V_DATE_OUT and/or V_DATE_IN enter the dates of 28/03/2013 and 29/03/2013. All other dates not included in the table for special leave will be treated according to the day they fall on (from Monday to Sunday). I hope my point is clear. Thank you in advance.
arms777 wrote:
I have already given a test for the table,
Frank pleased to display:
"examples of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from this data."
I do not see the second statement in the create table and insert statements. Do you expect to write us your data ourselfs?
However I'll try it from scratch
merge into LOAD_PROFILE_TEST t
a_l'_aide_de)
Select distinct
Decode (var_date, null, theday, profile_day) profile_day
BeO
Select
SUPERIOR (to_char (: V_DATE_OUT + (level 1), 'fmDAY')) theday
,: V_DATE_OUT + subsist (level 1)
of the double
connect by level<= :v_date_in="" -="" :v_date_out ="" +="">=>
)
REG_HOLIDAYS
where
subsist = var_date (+)) g
on (UPPER (t.PROFILE_DAY) = g.profile_day
)
When matched then update
SET LOAD_PROF2 = LOAD_PROF1 +: LOAD_DIFFPost edited by: chris227
Fixed: added update -
query to find concurrent programs defined in each queue of concurrent Manager
We have custom defined concurrent queues and then included applications / programs under him.
In this way, we are seggregating the load on multiple queues, and applications servers.
To check, I want to find what programs are running / actually provided for in the title of each queue.
I see the same thing from the application interface. How can I find the same form backend database.
TO THE
How can I tell which concurrent Manager handled a simultaneous [ID 344011.1] application/program
Find all programs assigned to the specialization Manager rules? [271283.1 ID]
Thank you
Hussein
-
SQL query to find approved projects that are open
Hello
Can anyone provide a SQL query which will display only the approved projects that are open.
Thank you
TitasTry this
Select project NAME of pa_projects_all
where project_status_code = 'APPROVED '.
and NVL (CLOSED_DATE, SYSDATE + 1) > SYSDATEThank you
Pradeep -
The links are crammed with words that overlap each other
When I do a search, the page with many links, however, the words are not readable because they are crowded together. The same thing happens on Facebook. I did my icons, but that has not solved the problem. Tried system restore and it didn't restore.
While you are on a website with this problem, hold down the CTRL key while you press the 0 (zero) in the upper part of the keyboard and see if it resets the size of text for more overlap.
-
Two fonts keep intersecting each other?
When I create buttons of menu on my master page and hyperlink them to different pages I get my policy that Montserrat is replaced by another, according to what is selected. If anyone has had this problem and if so is there a resolution?
Thank you.
Looks like you might have another policy applied to the active state. Carefully inspect all the States of the menu item as well as the label to the breast.
Abhishek
-
How to name a region created by paths that intersect
If I take a circle and divide it into quarters by adding horizontal and vertical lines that cross each other, how can I name these 4 areas that result so that one person can change the color of these four tasks programmatically when you export as a svg file? (no problem shading them in Illustrator using live paint - but I need to stick a label or name on each region for use outside of the program)
Thanks for any help.
Rennes,
If you have a (set) circle and a vertical line and a horizontal (two lines extending at least to circles), select the first line vertical and object > path > divide objects below, then do the same with the horizontal line (or in reverse). Divide objects below only work with one path at a time.
-
Both functions can call each other?
I'm convert code and you ran into two functions which call each other. While I seems to have converted the two functions in plsql ok, they compile, apparently because they Ref each other. As soon as I get off referring to a call from one function to the other function, they both compile.
I know that Oracle 10 g supports recursion; and on the surface of things, this situation is not very different from the recursion. If the two functions are correct, I would hope they would compile.
I couldn't find a good part by searching the forums on this topic... but I hope that someone will have some info on this issue.Hello
Lecaro wrote:
It must be something of that order. You and others have suggested creating a package. I never did it. Can I put all my functions in a single package, including the two who call each other, or should I put both functions in two separate package in order to avoid the same problem?You probably want to put the two functions which call each other in a single package, but you probably don't want to put each of the functions you have already written in a single package.
Usually, a package contains some logical grouping of procedures that call each other or dealing with the problems of the same nature. When you call a procedure in a package, the entire package is loaded into memory.
For example, I have a package called pk_dt that does various things on the dates (for example, if a specific date is a public holiday). Some functions in this package call others in the package, some do not, but I put them in the same package because I predict that any job that calls one has a good chance of the call to the other.
The permissions are another thing to consider when you bundle procedures in packages.
-
How can I draw dynamic data that I get a hardware DAQ against each other?
Hi all
I am trying to acquire voltage and current data of DAQ hardware. My goal is plotted against votlagein current a continuous path. As the votlage is increased at intervals of 1 Volt, every second I want to see how the current. However, this data is dynamic and I need help find how to draw in a single chart. Any thoughts on how to draw the two different dynamic data against each other in the same graph?
You help will be very appreciated.
Thank you
If I understand what you're saying, looks like you want to have the update of XY graph with each new data point (or points) acquired, but also choose to keep the previous data on the XY graph. If that's what you're after, I build on my previous example. For the method of use of the express VI build XY graph, you can simply double click on it and uncheck the "erase data on each call. For the other method of construction of the dashboard cluster, you will need to add a few records to offset to maintain the previous itterations table values. Here's the updated image:
Maybe you are looking for
-
Hello I have currently a crashed early 2011 MacBook Pro 15 "and have a friend who has a very good condition, as the new Mac Mini 2012 for $300. The Mac Mini has 4 GB of RAM and 500 GB of storage. My MBP has 16 GB of RAM and 1 TB storage. They told me
-
Satellite U500 (PSU52E) - where to get a replacement screen?
My laptop computer screen of my Satellite U500 (PSU52E) broke. Can someone recommend where I can buy a replacement screen? Thank you
-
Satellite P300-21F - display drivers error in the Windows XP support site!
Hello from Greece! Satellite P300-21st model PSPCCE, I bought 3 days ago and I am still installing display drivers for the ATI Mobility Radeon HD 4650 graphics card. The drivers that are provided on the official website of support are wrong, because
-
Windows XP SP3 - reader DVD - RW 'Incorrect function' on blank CD
I get an 'Incorrect function' error on both of my readers of DVD - RW on Windows XP. I investigated the issue for a few days and came away empty-handed. 1. I tried to delete upper/lower filters in the registry. This helped to ensure that they are det
-
My computer is a Pavilion dv7 - 6123cl. My operating system is windows 7. I get an error message indicating intelligently check that my hard drive is about to fail. When I use the tests diagnostic to check HP short and long check, it says that my