dbTalk Databases Forums  

Re: query

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Re: query in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Bruno Wolff III
 
Posts: n/a

Default Re: query - 01-18-2004 , 11:20 PM






On Sun, Jan 18, 2004 at 00:02:42 +1300,
Ankur Arora <"Ankur Arora"@clear.net.nz> wrote:
Quote:
hello there
i have a problem
i want to know the query for finding out aggregate

eg. i have a column named sum in table xyz

sum
----
2
4
7
5


i want a sql query that will give me another column alongwith this column as
aggregate

sum aggregate
-----
2 2
4 6
7 13
5 18


if u could help me i will be obliged as i really need it on urgent basis
Its possible to do something like this with subqueries as long as there
is some way (e.g. additional columns) to order the table.

Then you could do something like:

select "sum", (select sum("sum") from xyz b where b.id <= a.id) from xyz a
order by id;
This assumes there is a column named id which can be used to order the data.

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend



Reply With Quote
  #2  
Old   
Bruno Wolff III
 
Posts: n/a

Default Re: Query - 07-13-2004 , 01:58 PM






On Tue, Jul 13, 2004 at 13:07:36 -0500,
Eduardo Vázquez Rodríguez <evazquez (AT) insys-corp (DOT) com.mx> wrote:
Quote:
Hi I have a table called "master" which look like this


id_master | month | day | infotype
Serial> PK | <Varchar 3> | <Varchar 3> | <Varchar 5
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
1 | May | 27 | 121
2 | May | 27 | 122
3 | May | 27 | 123
4 | May | 28 | 121
5 | May | 28 | 122


Which Primary Key (id_master) is the Foreign Key (id_master) of another
table called "masterdetail" which look like this
This is the problem infotype needs to be referenced, not id_master.

Quote:
id_masterdetail id_master argument color
Serial> PK | <int4> | <Varchar 30> | <Varchar 10
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
1 | 121 | house | blue
2 | 121 | house | blue
3 | 121 | building | white
4 | 122 | building | white
5 | 122 | house | yellow


I try tu run a query to ask for all the arguments, which color has the value
"blue" and they had the date "May" "27"

I wrote something like this

select argument from masterdetail, master where color like 'blue'
and master.month like 'May'
and master.day like '27'
and master.id_master = masterdetail.id_master;
While eventually you want to change names and use '=' instead of 'like',
for the purposes of this question you want the last where condition to be:
and master.infotype = masterdetail.id_master::text;

Quote:

But I cant get the correct results!

How can I fix it?
---
Eduardo Vázquez Rodríguez <evazquez (AT) insys-corp (DOT) com.mx
Insys
Soluciones Integrales de Seguridad en TI
Tel (52 55) 5322 5218
Implantación
---

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)



Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.