Re: [SQL] need help

2013-02-21 Thread Jaime Casanova
On Thu, Feb 21, 2013 at 3:20 PM, denero team wrote: > Hi, > > 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. > [...] > > Now I really don't know how to do this. > > can you advise me more ? > I'm not really su

Re: [SQL] Summing & Grouping in a Hierarchical Structure

2013-02-21 Thread Alexander Gataric
I would use the recursive CTE to gather the hierarchical portion of the data you need and then join that CTE to another table or CTE with the other data you need. I had a situation like this at my job were organization info was in a hierarchal table and I needed to join it to two other tables. I cr

Re: [SQL] need help

2013-02-21 Thread Oliver d'Azevedo Cristina
Sorry, why do you need the joins? Best, Oliver Enviado via iPhone Em 21/02/2013, às 09:28 PM, Russell Keane escreveu: >>> Now I really don't know how to do this. >>> >>> can you advise me more ? >>> >>> >>> Thanks, >>> >>> Dhaval >> >> >> I think these are the sqls you are looking for: >

Re: [SQL] need help

2013-02-21 Thread Russell Keane
> > Now I really don't know how to do this. > > > > can you advise me more ? > > > > > > Thanks, > > > > Dhaval > > > I think these are the sqls you are looking for: > > SELECT pm.id as move_id, p.id as product_id, l.id as location_id > FROM product_move pm inner join product p on pm.product_id

Re: [SQL] need help

2013-02-21 Thread Russell Keane
> Consider following are data in each table > > Location : > id , name, code > 1, stock, stock > 2, customer, customer > 3, asset, asset > > Product : > id, name, code, location > 1, product1, p1, 1 > 2, product2, p2, 3 > > > Product_Move : > id, product_id, source_location, destination_locatio

Re: [SQL] need help

2013-02-21 Thread Oliver d'Azevedo Cristina
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, às 08:20 PM, denero team escreveu: > Hi, > > Thanks for replying me. yes you are right a

Re: [SQL] need help

2013-02-21 Thread denero team
Hi, 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. Consider following are data in each table Location : id , name, code 1, stock, stock 2, customer, customer 3, asset, asset Product : id, name, code, location

Re: [SQL] need help

2013-02-21 Thread Carlos Chapi
Hello, Maybe this query can help you SELECT p.name, l.name FROM location l INNER JOIN product_move m ON m.source_location = location.id INNER JOIN product p ON m.product_id = p.id WHERE p.id = $product_id AND m.datetime < $given_date ORDER BY datetime DESC LIMIT 1 It will return the name of the

[SQL] need help

2013-02-21 Thread denero team
Hi All, 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 (

Re: [SQL] Summing & Grouping in a Hierarchical Structure

2013-02-21 Thread Don Parris
Hi Mike, No Excel here. This is a strictly libre systems environment. I believe LibreOffice Calc has a similar tool though. And your suggestion might be a great one. On Mon, Feb 18, 2013 at 10:24 AM, Relyea, Mike wrote: > > From: pgsql-sql-ow...@postgresql.org [mailto: > pgsql-sql-ow...@post

Re: [SQL] Summing & Grouping in a Hierarchical Structure

2013-02-21 Thread Don Parris
Hi Alexander, I appreciate you taking time to reply to my post. I like the idea of the WITH RECURSIVE query, but... The two examples in the link you offered are not so helpful to me. For example, the initial WITH query shown uses a single table, and I wander how that might apply in my case, whe