sql - Create a view that shows from which table content comes -


i have little problem postgresql view have create school project.

i have 5 tables named:

  • input(inputid , distributorid , date)
  • inputline(inputid, objectid, ammount)
  • output(outputid, clientid, date)
  • outputline(outputid, objectid, ammount)
  • stock(objectid, ammount)

now need view shows me changes (per objectid) made in chronological order this:

| date       | type   | ammount in | ammount out | +------------+--------+------------+-------------+ | 10-10-2007 | input  | 10         |             | | 11-10-2007 | output |            | 5           | | 12-10-2007 | input  | 20         |             | 

i have absolutely no clue on how appreciate help. if more details needed, don't hesitate ask =)

select o.date, 'output' type, ol.amount amount_out, null amount_in   outputline ol join   output     o using (outputid)  union select i.date, 'input', null, il.amount   inputline il join   input     using (inputid) order  date, type; 

the order by clause after union or union all applies whole result set.

i order type additionally break ties date, input comes before output.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -