If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > PostgreSQL > Table subsetting and attribute comparison

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-28-11, 05:33
krontrex krontrex is offline
Registered User
 
Join Date: Sep 2010
Posts: 37
Table subsetting and attribute comparison

Dear all,
I have a following table

Code:
CREATE TABLE product
(
id varchar PRIMARY KEY,
height decimal,
width decimal,
weight decimal,
number int,
.
.

sampledate datetime PRIMARY KEY,
I have the following problem:
1) I need to create another table with the same attributes but only from these rows that have the latest sampling date (max(sampledate)). The sampling date denotes the beginning of the sampling and it is same for all products being sampled at the time.
First idea to solve this problem is to get all rows with the latest sampling date and put all these rows in new table
Code:
INSERT INTO current_product VALUES(SELECT * FROM PRODUCT WHERE sampledate=(SELECT MAX(sampledate) FROM PRODUCT))
Is there any more efficient way to do this like cut off the part of table on some condition
2) I need to check if there were some changes in attributes between products with the same id but different sample date. I can group the rows with the same id and then start checking each attribute but is there a more efficient way in solving this?
Thanks
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On