Sql query to get df -h output
Hi,
Please provide me sql query to get df -h output. I don't have server (Solaris) access to get df -h output.
I want to check the space availability on the mount point to increase space at the tablespace level.
Thank you..
sb92075 wrote:
SQL> host df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 220G 66G 144G 32% /
none 1.9G 308K 1.9G 1% /dev
none 1.9G 959M 896M 52% /dev/shm
none 1.9G 96K 1.9G 1% /var/run
none 1.9G 0 1.9G 0% /var/lock
none 1.9G 0 1.9G 0% /lib/init/rw
The "host" command executes on the client machine running sqlplus, not the server that the OP says he doesn't have access to.
Similar Messages
-
Sql query to get the given output
Hi Friends
My table data is given below
user transaction_date transaction_type
1 01-Aug-2011 a
1 02-Aug-2011 c
1 03-Aug-2011 a
1 03-Aug-2011 b
1 04-Aug-2011 a
1 04-Aug-2011 b
2 03-Aug-2011 a
2 03-Aug-2011 b
2 04-Aug-2011 c
2 04-Aug-2011 b
2 05-Aug-2011 a
2 05-Aug-2011 b
2 07-Aug-2011 a
2 07-Aug-2011 b
I want the count for each user as, how many times he did a transaction type 'b' immediately after transaction type a ?
Like the output for above data should be
user count
1 2
2 3
Thanks in advance :)Assuming there was information in the transaction date to indicate the sequence of the transactions then it would be something like...
SQL> ed
Wrote file afiedt.buf
1 with t as (select 1 as usr, to_date('01-Aug-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') as transaction_date, 'a' as transaction_type from dual union all
2 select 1, to_date('02-Aug-2011 00:00:00','DD-MON-YYYY HH24:MI:SS'), 'c' from dual union all
3 select 1, to_date('03-Aug-2011 00:00:00','DD-MON-YYYY HH24:MI:SS'), 'a' from dual union all
4 select 1, to_date('03-Aug-2011 00:00:01','DD-MON-YYYY HH24:MI:SS'), 'b' from dual union all
5 select 1, to_date('04-Aug-2011 00:00:00','DD-MON-YYYY HH24:MI:SS'), 'a' from dual union all
6 select 1, to_date('04-Aug-2011 00:00:01','DD-MON-YYYY HH24:MI:SS'), 'b' from dual union all
7 select 2, to_date('03-Aug-2011 00:00:00','DD-MON-YYYY HH24:MI:SS'), 'a' from dual union all
8 select 2, to_date('03-Aug-2011 00:00:01','DD-MON-YYYY HH24:MI:SS'), 'b' from dual union all
9 select 2, to_date('04-Aug-2011 00:00:00','DD-MON-YYYY HH24:MI:SS'), 'c' from dual union all
10 select 2, to_date('04-Aug-2011 00:00:01','DD-MON-YYYY HH24:MI:SS'), 'b' from dual union all
11 select 2, to_date('05-Aug-2011 00:00:00','DD-MON-YYYY HH24:MI:SS'), 'a' from dual union all
12 select 2, to_date('05-Aug-2011 00:00:01','DD-MON-YYYY HH24:MI:SS'), 'b' from dual union all
13 select 2, to_date('07-Aug-2011 00:00:00','DD-MON-YYYY HH24:MI:SS'), 'a' from dual union all
14 select 2, to_date('07-Aug-2011 00:00:01','DD-MON-YYYY HH24:MI:SS'), 'b' from dual
15 )
16 --
17 -- end of test data
18 --
19 select usr, sum(sum_ab) as sum_ab
20 from (
21 select usr
22 ,case when transaction_type = 'b'
23 and lag(transaction_type) over (partition by usr order by transaction_date) = 'a'
24 then 1
25 else 0
26 end as sum_ab
27 from t
28 )
29* group by usr
SQL> /
USR SUM_AB
1 2
2 3which is essentially the same as Etbin posted, but without the assumption that the ordering is by transaction_type. -
SQL query to get a list of relations between workitems
How can I create a SQL query to get a list of all problems with related changes? And all problems with related incidents?
I have tried to join the tables RelationshipTypeDim with ProblemDimKey and ChangeRequestDim, but the results are not correct.The relationships in the data warehouse can be kind of tricky. The relationships are contained in the WorkItemRelatesToWorkItemFactvw table. This table lists the related items by their WorkItemDimKey, so you cannot reference directly from the ChangeRequestDimvw
or ProblemDimvw. You will need to reference the WorkItemDimvw to get the WorkItemDimKey for each entry.
The query below will get all of the related work items from the Change Request class. The way the joins work is ChangeRequestDimvw gets the list of change requests. Then inner joins WorkItemDimvw to get the WorkItemDimKey for each CR. Then inner joins WorkItemRelatesToWorkItemFactvw
to get all of the CRs with related work items. Then inner joins the WorkItemDimvw again to get the ID of the related work item.
Now the tricky part is it appears that these relationship are set based on which item that created the relationship. So you need to union a second query that reverse the relationship on the WorkItemRelatesToWorkItemFactvw.
This query should give you a good start on getting the related work items. You can filter it down from here if you only want to include problems.
SELECT C.ID, WIWI.ID
FROM dbo.ChangeRequestDimvw C
INNER JOIN dbo.WorkItemDimvw WI ON
WI.EntityDimKey = C.EntityDimKey
INNER JOIN dbo.WorkItemRelatesToWorkItemFactvw AS WIRWI ON
WIRWI.WorkItemDimKey = WI.WorkItemDimKey
INNER JOIN dbo.WorkItemDimvw AS WIWI ON
WIWI.WorkItemDimKey = WIRWI.WorkItemRelatesToWorkItem_WorkItemDimKey
union
SELECT C.ID, WIWI.ID
FROM dbo.ChangeRequestDimvw C
INNER JOIN dbo.WorkItemDimvw WI ON
WI.EntityDimKey = C.EntityDimKey
INNER JOIN dbo.WorkItemRelatesToWorkItemFactvw AS WIRWI ON
WIRWI.WorkItemRelatesToWorkItem_WorkItemDimKey = WI.WorkItemDimKey
INNER JOIN dbo.WorkItemDimvw AS WIWI ON
WIWI.WorkItemDimKey = WIRWI.WorkItemDimKey
Order by C.ID
Matthew Dowst |
Blog | Twitter -
Sql query to get distinct count
Hi
I use SQL Server Management Studio
can I have a sql query to get count as shown below against each month column and name column to get distinct count.
for example if there is two rows with the same date period and same name then the count should be one in first row and zero in the next row of the same data.
Table Name: Table1
Column: Month, Name
Month
Name
Count
12/1/2012 0:00
AK
1
12/1/2012 0:00
AK
0
12/1/2012 0:00
AB
1
1/1/2013 0:00
AK
1
1/1/2013 0:00
AK
0
1/1/2013 0:00
AB
1
3/1/2013 0:00
AA
1
3/1/2013 0:00
AK
1
3/1/2013 0:00
AK
0
6/1/2013 0:00
AA
1
6/1/2013 0:00
AK
1
6/1/2013 0:00
AK
0
9/1/2013 0:00
AA
1
9/1/2013 0:00
AK
1
9/13/2013 0:00
AK
1
10/1/2013 0:00
AA
1
10/1/2013 0:00
AK
1
10/1/2013 0:00
AK
0Hi,
Thanks for the query but this query gives the total count like shown below
if see the second row in the below table AK for 2012-12-1 gives total count as 2 but need the query to show the first row as 1 and there after 0
query result
Month name cnt
2012-12-01 00:00:00.000 AB 1
2012-12-01 00:00:00.000 AK 2
2012-12-01 00:00:00.000 AK 2
2013-01-01 00:00:00.000 AB 1
2013-01-01 00:00:00.000 AK 2
2013-01-01 00:00:00.000 AK 2
2013-03-01 00:00:00.000 AA 1
2013-03-01 00:00:00.000 AK 2
2013-03-01 00:00:00.000 AK 2
2013-06-01 00:00:00.000 AA 1
2013-06-01 00:00:00.000 AK 2
2013-06-01 00:00:00.000 AK 2
2013-09-01 00:00:00.000 AA 1
2013-09-01 00:00:00.000 AK 1
2013-09-13 00:00:00.000 AK 1
2013-10-01 00:00:00.000 AA 1
2013-10-01 00:00:00.000 AK 2
2013-10-01 00:00:00.000 AK 2 -
SQL query to get the Datetime 06 hours prior to the table Datetime value
Hi Experts,
I'm just trying to create a SQL query to get the Datetime which should be 06 hours prior to my Table column value(Executiontime),
Eg: my Executiontime(column) value is 07:00AM means, this query should fetch the detail of first VMName from table at 01:00AM,
SQL Table Name: TestTable
Columns: VMName(varchar),status(varchar) Executiontime(Datetime)
SQL Query : Select Top 1 VMName from
TestTable where convert(date,Exeutiontime)=convert(date,getdate()) and
status='0' and ExecutionTime > dateadd(hour,6,getdate())
Request someone to alter this Query to my requirement or give me the new one.
Regards,
Sundar
SundarHi All,
Thanks for your Prompt response. I tried the below queries, but still I don't have any luck. Actually the queries are returning the value before the condition met (say when the time difference is more than 06 hours). I want the
query to return exactly @ 06 hour difference or less than 06 hours,
Query 01: Select Top 1 VMName from TestTable where
convert(date,Exeutiontime)=convert(date,getdate())
and status='0'
and ExecutionTime >
dateadd(hour,-6,getdate())
Query 02: Select
Top 1 VMName from TestTable where
status='0'
and ExecutionTime >
dateadd(hour,-6,getdate())
Query 03: Select
Top 1 VMName from TestTable where status='0'
and ExecutionTime >
dateadd(hour,-6,ExecutionTime)
Can someone point out the mistake please.
Regards,
Sundar
Sundar -
SQL query to get the list of approvals
Hi,
Could someone let me know the SQL query to get the list of all the pending approvals for a user in OIM 11g R2.
ThanksThere are a few ways to do this:
- The easiest would be to use a Relationship Query from the CMC. To do this, go to the Universes section on the CMC, right click on the relevant universe, select tools >> Check Relationships.
- Use Query Builder. You will need more than one query to pull the information you need. You could try something like the below (for Webi)
SELECT SI_NAME, SI_WEBI, SI_DATACONNECTION FROM CI_APPOBJECTS
WHERE SI_KIND = 'universe' and SI_NAME = 'Universe Name'
This will give you a list of Webi Reports by SI_ID.
You'll need another query to list Webi report names:
SELECT SI_NAME FROM CI_INFOOBJECTS WHERE SI_ID IN (SI_ID from query above)
- This is trivial via Auditing / the Activity universe. This of course will only return reports that have already run.
Best.
Srinivas -
SQL query to get last 6 months records neglect the current month
Hi All;
I need help with
sql query to get last 6 months records neglect the current month
Any help much appreciated
Thanks
Pradnya07SELECT <> FROM tbl WHERE dt >=dateadd(month,-6,GETDATE())
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
SQL query to get last 10 records in the table?
Hi,
Can anyone tell me the SQL query to get last 10 records in the table?
Thanks!!
MCPPlease, define what "last" means. Sets are unordered by definition, so if you want to retrieve rows from a table in a specific order you need to specify what that order is - e.g. by maintaining a value in a column (or a combination of columns) that you can use in the ORDER BY clause of the SELECT statement.
If, for instance, you kept the time when the row was inserted in a special column (InsertedTime), you could use this in your query like this:
select top (10)
<column list>
from <table or view>
where <restriction(s)>
order by InsertedTime desc;
ML
Matija Lah, SQL Server MVP
http://milambda.blogspot.com -
Dear Gurus, Can i have SQL query to get Ar cash receipt appled lines details in R12
Dear Gurus, Can i have SQL query to get Ar cash receipt appled lines details in R12
I need to get ar and ap details from GL through xla.For ex: Reference1,reference2,reference3,reference4,reference 5, in 11i these column values are displayed in gl_je_lines where as in R12 we need to join xla tables with gl_sl_link_id and gl_sl_link_table
Can someone provide query to get subledger details particularly ar and ap?.How are the AP & GL Journal Tables linked? [ID 1188714.1]
R12 Mapping Between Subledger Tables, SLA and GL Tables [ID 871622.1]
eTRM
http://etrm.oracle.com/
Thanks,
Hussein -
SQL query to get transaction detail from DEFERRED_TRAN_ID
Hi,
I'm using Oracle Advance Replication and get the transaction detail from Enterprise Manager Console.
So instead of using the console.
Is there a way any SQL query which get transaction details like SQL query fired, old and new column value etc from DEFERRED_TRAN_ID.
thanksquote:
Originally posted by:
lucapac
I have two tables: tblWorkers and tblSkills. tblWorkers has a
column, Skills, which is populated from a multiple-checkbox form
field with one or more skill_IDs from tblSkills, so each
tblWorkers.Skills consists of a list of one or more comma-delimited
values. For any Skill_ID, I need to generate a listing of all
Workers with the corresponding skill, so I have tried to do
something along the lines of SELECT WorkerName FROM tblWorkers
WHERE Skills IN (Skills, #FORM.Skill_ID#) ... or WHERE Skills IN
(ListFind(Skills, #FORM.Skill_ID#)) ... etc. ??? My results (once I
got data type mismatches out of the way) return all Workers, not
just those with the desired Skill. There must be an easy way to do
this ... How do people with a bit more CF/SQL experience than I
have do this???
As Kronin implied, we normalize our databases. If you don't
understand that answer, the book "Database Design for Mere Mortals"
is often mentioned on this forum. -
SQL Query to get Project Plan Name and Resource Name from Reporting database of Project Server 2007
Can you please help me to write an SQL Query to get Project Plan Name and Resource Name from Reporting database of Project Server 2007. Thanks!!
Refer
http://gallery.technet.microsoft.com/projectserver/Server-20072010-SQL-Get-a99d4bc6
SELECT
dbo.MSP_EpmAssignment_UserView.ProjectUID,
dbo.MSP_EpmAssignment_UserView.TaskUID,
dbo.MSP_EpmProject_UserView.ProjectName,
dbo.MSP_EpmTask_UserView.TaskName,
dbo.MSP_EpmAssignment_UserView.ResourceUID,
dbo.MSP_EpmResource_UserView.ResourceName,
dbo.MSP_EpmResource_UserView.ResourceInitials
INTO #TempTable
FROM dbo.MSP_EpmAssignment_UserView INNER JOIN
dbo.MSP_EpmProject_UserView ON dbo.MSP_EpmAssignment_UserView.ProjectUID = dbo.MSP_EpmProject_UserView.ProjectUID INNER JOIN
dbo.MSP_EpmTask_UserView ON dbo.MSP_EpmAssignment_UserView.TaskUID = dbo.MSP_EpmTask_UserView.TaskUID INNER JOIN
dbo.MSP_EpmResource_UserView ON dbo.MSP_EpmAssignment_UserView.ResourceUID = dbo.MSP_EpmResource_UserView.ResourceUID
SELECT
ProjectUID,
TaskUID,
ProjectName,
TaskName,
STUFF((
SELECT ', ' + ResourceInitials
FROM #TempTable
WHERE (TaskUID = Results.TaskUID)
FOR XML PATH (''))
,1,2,'') AS ResourceInitialsCombined,
STUFF((
SELECT ', ' + ResourceName
FROM #TempTable
WHERE (TaskUID = Results.TaskUID)
FOR XML PATH (''))
,1,2,'') AS ResourceNameCombined
FROM #TempTable Results
GROUP BY TaskUID,ProjectUID,ProjectName,TaskName
DROP TABLE #TempTable
-Prashanth -
Sql query to get numbers from 0 to 99
How can we write an sql query to get values from 0 to 99 ... this shouldn't be coming from any table
Bawer wrote:
Result: (quickly replied by oracle)
SQL-Error: ORA-30009 (Not enough memory for connect by - 1GB reserved for oracle on VirtualBox)Oracle version? Takes about 8 seconds on my:
SQL> select * from v$version
2 /
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for 32-bit Windows: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
Elapsed: 00:00:00.14
SQL> select count(*) from (
2 SELECT LEVEL - 1
3 FROM DUAL
4 CONNECT BY LEVEL <= 10000000
5 )
6 /
COUNT(*)
10000000
Elapsed: 00:00:07.76
SQL> SY. -
SQL query to get DDL for Adding PK.
Guys,
I'm looking for SQL query that gets me the "ALTER TABLE <TABLE_NAME> ADD CONSTRAINT <constraint_name> PRIMARY KEY (X,Y,...);" statments of all tables in my schema containing Primary Keys.
Could someone help me with the query please?
Regards,
BhagatYou need this
SELECT 'ALTER TABLE '||table_name||' ADD CONSTRAINT '||constraint_name||' PRIMARY KEY ('||column_name||');'
FROM ( SELECT uc.table_name
,uc.constraint_name
,RTRIM (XMLAGG (XMLELEMENT (ucc, column_name || ',')).extract ('//text()'), ',') column_name
FROM user_constraints uc
,user_cons_columns ucc
WHERE uc.constraint_type = 'P'
AND uc.constraint_name = ucc.constraint_name
GROUP BY uc.table_name
,uc.constraint_name
ORDER BY table_name; Regards
Arun -
Oracle SQL query for getting specific special characters from a table
Hi all,
This is my table
Table Name- Table1
S.no Name
1 aaaaaaaa
2 a1234sgjghb
3 a@3$%jkhkjn
4 abcd-dfghjik
5 bbvxzckvbzxcv&^%#
6 ashgweqfg/gfjwgefj////
7 sdsaf$([]:'
8 <-fdsjgbdfsg
9 dfgfdgfd"uodf
10 aaaa bbbbz#$
11 cccc dddd-/mnm
The output has to be
S.no Name
3 a@3$%jkhkjn
5 bbvxzckvbzxcv&^%#
7 sdsaf$([]:'
8 <-fdsjgbdfsg
10 aaaa bbbbz#$
It has to return "Name" column which is having special characters,whereas some special chars like -, / ," and space are acceptable.
The Oracle query has to print columns having special characters excluding -,/," and space
Can anyone help me to get a SQL query for the above.
Thanks in advance.You can achieve it in multiple ways. Here are few.
SQL> with t
2 as
3 (
4 select 1 id, 'aaaaaaaa' name from dual union all
5 select 2 id, 'a1234sgjghb' name from dual union all
6 select 3 id, 'a@3$%jkhkjn' name from dual union all
7 select 4 id, 'abcd-dfghjik' name from dual union all
8 select 5 id, 'bbvxzckvbzxcv&^%#' name from dual union all
9 select 6 id, 'ashgweqfg/gfjwgefj////' name from dual union all
10 select 7 id, 'sdsaf$([]:''' name from dual union all
11 select 8 id, '<-fdsjgbdfsg' name from dual union all
12 select 9 id, 'dfgfdgfd"uodf' name from dual union all
13 select 10 id, 'aaaa bbbbz#$' name from dual union all
14 select 11 id, 'cccc dddd-/mnm' name from dual
15 )
16 select *
17 from t
18 where regexp_like(translate(name,'a-/" ','a'), '[^[:alnum:]]');
ID NAME
3 a@3$%jkhkjn
5 bbvxzckvbzxcv&^%#
7 sdsaf$([]:'
8 <-fdsjgbdfsg
10 aaaa bbbbz#$
SQL> with t
2 as
3 (
4 select 1 id, 'aaaaaaaa' name from dual union all
5 select 2 id, 'a1234sgjghb' name from dual union all
6 select 3 id, 'a@3$%jkhkjn' name from dual union all
7 select 4 id, 'abcd-dfghjik' name from dual union all
8 select 5 id, 'bbvxzckvbzxcv&^%#' name from dual union all
9 select 6 id, 'ashgweqfg/gfjwgefj////' name from dual union all
10 select 7 id, 'sdsaf$([]:''' name from dual union all
11 select 8 id, '<-fdsjgbdfsg' name from dual union all
12 select 9 id, 'dfgfdgfd"uodf' name from dual union all
13 select 10 id, 'aaaa bbbbz#$' name from dual union all
14 select 11 id, 'cccc dddd-/mnm' name from dual
15 )
16 select *
17 from t
18 where translate
19 (
20 lower(translate(name,'a-/" ','a'))
21 , '.0123456789abcdefghijklmnopqrstuvwxyz'
22 , '.'
23 ) is not null;
ID NAME
3 a@3$%jkhkjn
5 bbvxzckvbzxcv&^%#
7 sdsaf$([]:'
8 <-fdsjgbdfsg
10 aaaa bbbbz#$
SQL> -
Sql query to get union of matching rows
I want to write a sql query that shows union f all the [Type] for each [Key] if [Key] has atleast one [Type] in common and for non matched [Key]s it will return the row as it is.
For example In the sql table below [Key] '1' and '2' has [Type] 'B' in common and [Key] '1' and '4' has [Type] 'A' in common. In this case [Key] '1', '2' and '4' are related so result will be union of [Type]s in [Key]s '1', '2' and '4' which are 'A', 'B', 'C'
and 'E' for each [Key]. And [Key] '3' has no [Type] in common so it will return itself.
Input:
declare @categories table ([Key] int, [Type] Char(1))
insert into @categories ([Key], [Type]) values (1, 'A')
insert into @categories ([Key], [Type]) values (1, 'B')
insert into @categories ([Key], [Type]) values (2, 'B')
insert into @categories ([Key], [Type]) values (2, 'C')
insert into @categories ([Key], [Type]) values (3, 'D')
insert into @categories ([Key], [Type]) values (4, 'E')
insert into @categories ([Key], [Type]) values (4, 'A')
insert into @categories ([Key], [Type]) values (5, 'F')
insert into @categories ([Key], [Type]) values (5, 'G')
insert into @categories ([Key], [Type]) values (6, 'G')
insert into @categories ([Key], [Type]) values (6, 'H')
Desired output:
Key Type
1 A
1 B
1 C
1 E
2 A
2 B
2 C
3 D
4 A
4 B
4 E
5 F
5 G
5 H
6 F
6 G
6 H
The data element names are wrong. KEY is a reserved word; “Categories" and "type" are called attribute properties in ISO-11179 rules. Matthias Kläy is right; this is a graph problem in disguise, but you can do it with set theory to get what are called
equivalence classes.
An edge in a graph has two nodes. Some authors allow a single node to count as a edge, but a better way is to put the same node on both ends of the edge. Here is the graph in a table with all the needed constraints. This is why you should post DDL and not be
so rude.
DROP TABLE Graph;
CREATE TABLE Graph
(edge INTEGER NOT NULL,
node_1 CHAR(1) NOT NULL,
node_2 CHAR(1) NOT NULL,
CHECK (node_1 <= node_2),
PRIMARY KEY (node_1, node_2));
Here is your data in the correct format.
INSERT INTO Graph
VALUES
(1, 'A', 'B'),
(2, 'B', 'C'),
(3, 'D', 'D'), -- orphan node
(4, 'A', 'E'),
(5, 'F', 'G'),
(6, 'G', 'H');
Now Google Warshall's Algorithm. It uses three nested loops and an adjacency array. This is very clean and fast in a procedural language. Not so much in SQL. Let us do this in steps:
WITH X1 (edge, node1_1, node1_2, node2_1, node2_2 )
AS
(SELECT CASE WHEN G1.edge <> G2.edge
THEN G1.edge ELSE G2.edge END,
G1.node_1, G1.node_2,
G2.node_1, G2.node_2
FROM Graph AS G1, Graph AS G2
WHERE G1.node_1 IN (G2.node_1, G2.node_2)
AND G1.edge <> G2.edge),
X2 (edge, node_1, node_2)
AS
(SELECT edge,
CASE WHEN node1_1 IN (node2_1, node2_2) THEN node1_2 ELSE node1_1 END,
CASE WHEN node2_1 IN (node1_1, node1_2) THEN node2_2 ELSE node2_1 END
FROM X1)
SELECT DISTINCT edge,
CASE WHEN node_1 < node_2 THEN node_1 ELSE node_2 END,
CASE WHEN node_2 < node_1 THEN node_1 ELSE node_2 END
FROM X2;
The X1 subquery gets the paths of length two. The X2 subquery removes the middle node and creates a new sorted edge. Insert these new rows into Graphs, if they are not there. Repeat the process until no more rows are added.
DROP TABLE Graph;
CREATE TABLE Graph
(edge INTEGER NOT NULL,
node_1 CHAR(1) NOT NULL,
node_2 CHAR(1) NOT NULL,
CHECK (node_1 <= node_2),
PRIMARY KEY (node_1, node_2));
INSERT INTO Graph
VALUES
(1, 'A', 'B'),
(2, 'B', 'C'),
(3, 'D', 'D'), -- orphan node
(4, 'A', 'E'),
(5, 'F', 'G'),
(6, 'G', 'H');
Here is the monster rolled up into a single statement.
INSERT INTO Graph
SELECT DISTINCT edge,
CASE WHEN node_1 < node_2 THEN node_1 ELSE node_2 END,
CASE WHEN node_2 < node_1 THEN node_1 ELSE node_2 END
FROM (SELECT edge,
CASE WHEN node1_1 IN (node2_1, node2_2) THEN node1_2 ELSE node1_1 END,
CASE WHEN node2_1 IN (node1_1, node1_2) THEN node2_2 ELSE node2_1 END
FROM
(SELECT CASE WHEN G1.edge < G2.edge
THEN G1.edge ELSE G2.edge END,
G1.node_1, G1.node_2,
G2.node_1, G2.node_2
FROM Graph AS G1, Graph AS G2
WHERE G1.node_1 IN (G2.node_1, G2.node_2)
AND G1.edge <> G2.edge) AS X1(edge,node1_1, node1_2, node2_1, node2_2) )
AS X2(edge, node_1, node_2)
EXCEPT
SELECT * FROM Graph;
SELECT * FROM Graph ORDER BY edge, node_1, node_2;
1 A B
1 A C
1 B E
1 C E
2 B C
3 D D
4 A E
5 F G
5 F H
6 G H
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL
Maybe you are looking for
-
Problem to open a report on view preview on R2
I have I problem, on R1, the next URL It's working very good, when I call on another application. http://localhost/crystalreportviewers11/viewrpt.aspx?id=46391&apsauthtype=secEnterprise&cmd=EXPORT&EXPORT_FMT=crxf_pdf:0&apsuser=administrator&apspasswo
-
Thoughts are to allow groups of individuals mobile numbers to be shared across larger organizations, from within a PDF document, that the mobile numbers would be clickable, and open up a Text or instant messaging application on either the computer, t
-
Best practice for documenting Hyperion BQY's?
I was wondering if anyone had anyone had any suggestions on the best way to document a BQY within the BQY itself? I do use comments inside the calculated fields but I was looking for a way to document the complete BQY. Any thoughts or ideas would be
-
"Error on Page" permission denied
We have several users in our SRM system that encounter an "Error on Page" (permission denied) javascript error when their page is left idle for 5-10 minutes. This is in spite of the timeout settings being set as follows: SRM Server rdisp/gui_auto_lo
-
Save takes MUCH longer with images placed
When I have images placed in Illustrator, even just a few small ones, Save takes much longer..so long that it can be 20 seconds before I even see the progress bar, and after that the saving actually happens. Is there a way around this, or are we stuc