Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U8coD-00074r-4u for pgsql-sql@arkaria.postgresql.org; Thu, 21 Feb 2013 20:32:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1U8coB-0003Vi-Ug for pgsql-sql@arkaria.postgresql.org; Thu, 21 Feb 2013 20:31:59 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U8coA-0003Tw-Mb for pgsql-sql@postgresql.org; Thu, 21 Feb 2013 20:31:59 +0000 Received: from we-in-x0229.1e100.net ([2a00:1450:400c:c03::229] helo=mail-we0-x229.google.com) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U8co8-0001hk-Ll for pgsql-sql@postgresql.org; Thu, 21 Feb 2013 20:31:57 +0000 Received: by mail-we0-f169.google.com with SMTP id t11so8090572wey.14 for ; Thu, 21 Feb 2013 12:31:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:references:in-reply-to:mime-version :content-transfer-encoding:content-type:message-id:cc:x-mailer:from :subject:date:to; bh=bRUcr8WcDiSbrL+Rc+ByuKLj9/n2cTwbLKsHJLjGQA8=; b=nXMccEZE0lHq8V8XhMNuPAMLY8hWhtBhP5DWpfZxpQXwsHRZfqrVA0mdZBYb+f8cHm sVJDCCj0mQVo1g1Yv4RhQymEXPpIvmAs1gBIhHLlTZV+Y5e2r6rl8GuYBxKzidsblCj4 hJVXnkojBSXw2b9BbpQ69DkF5H6vgRUvrXHIXn+bWm6LzIHTCHp3NEJDASu6S3GuIO9K IQcf0snNyAKgCYBzgaMcphRAyn+zeGd0joufG79vqtB/WJsAfmmpKXPHskZEdwqqCXuv 2lFMEfSJm54b/CcnkLLFcKkwP1z7UYonHpApFpibHfq1WhzL5RejN+tbIdpMKXfSETLx WE3A== X-Received: by 10.180.14.233 with SMTP id s9mr42775235wic.25.1361478714316; Thu, 21 Feb 2013 12:31:54 -0800 (PST) Received: from [10.33.173.239] (177.26.136.95.rev.vodafone.pt. [95.136.26.177]) by mx.google.com with ESMTPS id bg5sm569371wib.8.2013.02.21.12.31.48 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 21 Feb 2013 12:31:52 -0800 (PST) References: In-Reply-To: Mime-Version: 1.0 (iPhone Mail 8L1) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Message-Id: <76AB0A60-BB3E-4674-881A-F0DF0ECE7F0B@gmail.com> Cc: Carlos Chapi , "pgsql-sql@postgresql.org" X-Mailer: iPhone Mail (8L1) From: Oliver d'Azevedo Cristina Subject: Re: need help Date: Thu, 21 Feb 2013 20:35:00 +0000 To: denero team X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org SELECT move_id, product_id,destination_location as location_id FROM product_move Where datetime BETWEEN $first AND $last Have you tried something like this? Best, Oliver Enviado via iPhone Em 21/02/2013, =C3=A0s 08:20 PM, denero team escreve= u: > Hi, >=20 > Thanks for replying me. yes you are right at some level for my case. > but its not what I want. I am explaining you a case by example. >=20 > Consider following are data in each table >=20 > Location : > id , name, code > 1, stock, stock > 2, customer, customer > 3, asset, asset >=20 > Product : > id, name, code, location > 1, product1, p1, 1 > 2, product2, p2, 3 >=20 >=20 > Product_Move : > id, product_id, source_location, destination_location, datetime > 1, 1, Null, 1, 2012-10-15 10:00:00 > 2, 2, Null, 1, 2012-10-15 10:05:00 > 3, 2, 1, 3, 2012-12-01 09:00:00 >=20 > Please review all data , you can see, current location of product1 > (p1) is 1 (stock) and current location of product2 (p2) is 3 (asset). >=20 > now i want to find location of all products for given period >=20 > for example : 2012-11-01 to 2012-11-30, then i need result should be like= below > move_id, product_id, location_id > 1, 1, 1 > 2, 2, 1 >=20 > another example : 2012-11-01 to 2012-12-31 > move_id, product_id, location_id > 1, 1, 1 > 2, 2, 1 > 3, 2, 3 >=20 > Now I really don't know how to do this. >=20 > can you advise me more ? >=20 >=20 > Thanks, >=20 > Dhaval >=20 >=20 > On Fri, Feb 22, 2013 at 1:26 AM, Carlos Chapi > wrote: >> Hello, >>=20 >> Maybe this query can help you >>=20 >> SELECT p.name, l.name >> FROM location l >> INNER JOIN product_move m ON m.source_location =3D location.id >> INNER JOIN product p ON m.product_id =3D p.id >> WHERE p.id =3D $product_id >> AND m.datetime < $given_date >> ORDER BY datetime DESC LIMIT 1 >>=20 >> It will return the name of the product and the location for a given id a= nd >> date. >>=20 >>=20 >> 2013/2/21 denero team >>>=20 >>> Hi All, >>>=20 >>> I need some help for my problem. >>> Problem : >>> I have following tables >>> 1. Location : >>> id, name, code >>> 2. Product >>> id, name, code, location ( ref to location table) >>> 2. Product_Move >>> id, product_id ( ref to product table), source_location (ref to >>> location table) , destination_location ( ref to location table) , >>> datetime ( date when move is created) >>>=20 >>> now i want to know for given period of dates, where is the product >>> actually. >>>=20 >>> can anyone help me ?? >>>=20 >>> Thanks, >>>=20 >>> Dhaval >>>=20 >>>=20 >>> -- >>> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) >>> To make changes to your subscription: >>> http://www.postgresql.org/mailpref/pgsql-sql >>=20 >>=20 >=20 >=20 > --=20 > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql --=20 Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql