Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
12-01-2004, 06:04 PM
|
#1
|
LQ Newbie
Registered: Nov 2004
Distribution: kde
Posts: 1
Rep:
|
Recursive Query
Hello, I am doing a project in db2. But I am not sure how to create a recursive query.
THanks
Javier Magana 
|
|
|
12-01-2004, 07:46 PM
|
#2
|
LQ Guru
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870
|
do a search on google for "db2 recursive query" (without the quotes) and you'll get lots of information...
i just did that search, and among the results was this example from the ibm website:
Code:
-----------------------------------------------------------------------------
-- Licensed Materials - Property of IBM
--
-- Governed under the terms of the International
-- License Agreement for Non-Warranted Sample Code.
--
-- (C) COPYRIGHT International Business Machines Corp. 1995 - 2002
-- All Rights Reserved.
--
-- US Government Users Restricted Rights - Use, duplication or
-- disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
-----------------------------------------------------------------------------
--
-- SOURCE FILE NAME: flt.db2
--
-- SAMPLE: How to do a RECURSIVE QUERY
--
-- SQL STATEMENTS USED:
-- DROP TABLE
-- CREATE TABLE
-- INSERT
-- SELECT
--
-- OUTPUT FILE: flt.out (available in the online documentation)
-----------------------------------------------------------------------------
--
-- For more information about the command line processor (CLP) scripts,
-- see the README file.
--
-- For information on using SQL statements, see the SQL Reference.
--
-- For the latest information on programming, building, and running DB2
-- applications, visit the DB2 application development website:
-- http://www.software.ibm.com/data/db2/udb/ad
-----------------------------------------------------------------------------
create table flights (source varchar ( 8 ),
destination varchar ( 8 ),
d_time integer ,
a_time integer ,
cost smallint ,
airline varchar ( 8 ));
INSERT INTO FLIGHTS VALUES ( 'Paris' , 'Detroit' , null,null, 700 , 'KLM' ),
( 'Paris' , 'New York' , null,null, 600 , 'KLM' ),
( 'Paris' , 'Toronto' , null,null, 750 , 'AC' ),
( 'Detroit' , 'San Jose' , null,null, 400 , 'AA' ),
( 'New York' , 'Chicago' , null,null, 200 , 'AA' ),
( 'Toronto' , 'Chicago' , null,null, 275 , 'AC' ),
( 'Chicago' , 'San Jose' , null,null, 300 , 'AA' );
WITH
REACH (SOURCE, DESTINATION, COST, STOPS) AS
( SELECT SOURCE, DESTINATION, COST, CAST( 0 AS SMALLINT )
FROM FLIGHTS
WHERE SOURCE = 'Paris'
UNION ALL
SELECT R.SOURCE, F.DESTINATION, CAST(R.COST+F.COST AS SMALLINT ), CAST(R.STOPS+ 1 AS SMALLINT )
FROM REACH R, FLIGHTS F
WHERE R.DESTINATION=F.SOURCE
AND R.STOPS < 5
)
SELECT DESTINATION, COST, STOPS FROM REACH;
drop table flights;
Last edited by win32sux; 12-01-2004 at 07:47 PM.
|
|
|
All times are GMT -5. The time now is 03:20 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|