Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 26th, 2006, 09:05 AM
vbaRstat vbaRstat is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 9 vbaRstat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 19 m 51 sec
Reputation Power: 0
How tu use "for select" to obtain a temporary table

I have this table:

f1 f2 f3

5606 1 111111
5607 1 222222
5608 1 333333
5609 1 444444
5606 2 555555
5607 2 666666
5608 2 777777

and I need to obtain :

f1_a f1_b f2 f3_a f3_b f3_a - f3_b

5606 5607 1 111111 222222 -111111
5606 5608 1 111111 333333 -222222
5606 5609 1 111111 444444 -333333
5607 5608 1 222222 333333 -111111
5607 5609 1 222222 444444 -222222
5608 5609 1 333333 444444 -111111
5606 5607 2 555555 666666 -111111
5606 5608 2 555555 777777 -222222
5607 5608 2 666666 777777 -111111


For each f2, each f1 is paired with each subsequent and the value reported into f3 can be compared.

(the value reported into f3 are only as example, they will be different )

(ps: from a statistical point of view, I need to obtain the combinations)

# vbaRstat #

Reply With Quote
  #2  
Old October 26th, 2006, 02:23 PM
pabloj's Avatar
pabloj pabloj is online now
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,907 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 8 h 24 m 58 sec
Reputation Power: 279
Don't you just need a carthesian product of the table joined with itself like
sql Code:
Original - sql Code
  1. SELECT
  2. c.cust_no, c.customer, d.cust_no, d.customer, c.cust_no - d.cust_no AS delta
  3. FROM
  4. CUSTOMER c, customer d;
? (example can be run on standard employee.fdb)

Reply With Quote
  #3  
Old October 27th, 2006, 02:49 AM
vbaRstat vbaRstat is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 9 vbaRstat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 19 m 51 sec
Reputation Power: 0
Quote:
Originally Posted by pabloj
Don't you just need a carthesian product of the table joined with itself like
sql Code:
Original - sql Code
  1. SELECT
  2. c.cust_no, c.customer, d.cust_no, d.customer, c.cust_no - d.cust_no AS delta
  3. FROM
  4. CUSTOMER c, customer d;
? (example can be run on standard employee.fdb)


The cartesian procudt is what I want but the table I'm using is big.
But probably I'm not very able to develop query with a good performance.
For example, I have a a table with 700.000 records composed in this way:

tb1(cust_no1, cust_no2, cod_quality, data_cuple).

I have another table:

tb2(cust_no, cod_quality, value) with about 200.000 records.

What I need is:

SELECT A.cust_no1, A.cust_no2, A.cod_quality, A.data_cuple, B.value, C.value
FROM (TB1 A LEFT JOIN TB2 B ON (A.CUST_NO1=B.CUST_NO AND A.COD_QUALITY=B.COD_QUALITY))
LEFT JOIN TB2 C ON
(A.CUST_NO2=C.CUST_NO AND A.COD_QUALITY=C.COD_QUALITY)


The result should be a table with at most 700.000 records, but the query it's too slow (more than 4 minutes, it's strange or it's the normality?).
I have deloped the same database in Access, with the same table and records and I obtain the result in at most 1 minute.
But Firebird is not efficient with left join?......:-).....but I think that the result of the query depends on my capability (very poor) in firebird.....(the db in firebird, however, is based on indices, and I don't understand where is the problem).

So I thought that a procedure with a For select could be a solution to reduce the number of records to "fetch".
Some comments? thanks a lot

# vbaRstat #

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > How tu use "for select" to obtain a temporary table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT