Re: [SQL] help yourself by helping others

2003-07-13 Thread Rajesh Kumar Mallah
dear ali,

something like

select machine,date_part('day' , date) , sum(withdrawals) from 
Table where date_part('month' , date)='month in question' group by
machine,date_part('day' , date) ;

will give you agrregated withdrawals by machine and day,
use the frontend language  for formatting it.

note that it will not display the days for which there
has been no withdrawls. If u need to report them also 0
then create a table that holds 1 year of dates and 
left or right join the output of first query with it.
exact query is not being provided , its just an idea.



regds
mallah.


On Friday 04 Apr 2003 4:40 pm, Ali Adams wrote:
> Dear All,
>
> I am new to Relational Databases and SQL and my background in ODBs is
> clouding my way to solving what seems to be a simple problem. I am sure
> many of you have met it many times.
>
> OK, I have a table as follows:
>
>
> ID Machine   Date Withdrawals
> 1  1  01/01/20031101
> 2  2  01/01/20032101
> 3  3  01/01/20033101
>
> 4  1  02/01/20031102
> 5  2  02/01/20032102
>
> 6  1  03/01/20031103
> 7  3  03/01/20033103
>
> 8  2  04/01/20032104
> 9  4  04/01/20034104
>
> And i would like to create a monthly withdrawals report as follows:
>
> Machine   Day1  Day2  Day3  Day4
> .. Day31 1 11 
> 12  13   0  0 2
> 21  22  024
> 0 3 31  033   0
>  0 4  00   0   
>  0 0
>
> Can you please help?
>
> Many thanks in advance.
>
> Ali
> 
> www.geocities.com/aliadams


---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [SQL] trigger proceedures in sql

2003-07-13 Thread Jan Wieck
Rajesh Kumar Mallah wrote:
Yes of course!
contrib/dbmirror does execute a procedure written in 'C'
called recordchange()  ON update , insert , delete.
If you need help in getting its source lemme know.
regds
Mallah.
On Thursday 10 Jul 2003 11:10 am, adivi wrote:
hi,

  can trigger proceedures ( procedures to be executed from within a
trigger ) not be written in sql.
  i was looking for examples and can find proceedures in 'c' only.
Trigger procedures can also be written in many procedural languages like 
PL/Perl, PL/Tcl and PL/pgSQL (what you should be looking at closer). 
Examples for PL/pgSQL can be found in the regression test.

Jan

--
#==#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.  #
#== [EMAIL PROTECTED] #
---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


[SQL] Replacing a simple nested query?

2003-07-13 Thread Steve Wampler

I've got a simple nested query:

  select * from attributes where id in (select id from
 attributes where (name='obsid') and (value='oid00066'));

that performs abysmally.  I've heard this described as the
'classic WHERE IN' problem.

Is there a better way to obtain the same results?  The inner
select identifies a set of ids (2049 of them, to be exact)
that are then used to locate records that have the same id
(about 30-40K of those, including the aforementioned 2049).

Thanks!
-Steve

-- 
Steve Wampler -- [EMAIL PROTECTED]
Quantum materiae materietur marmota monax si marmota
monax materiam possit materiari?

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faqs/FAQ.html


Re: [SQL] Replacing a simple nested query?

2003-07-13 Thread Joe Conway
Steve Wampler wrote:
I've got a simple nested query:

  select * from attributes where id in (select id from
 attributes where (name='obsid') and (value='oid00066'));
that performs abysmally.  I've heard this described as the
'classic WHERE IN' problem.
I may be missing something, but why can't you just do:
  select * from attributes where name='obsid' and value='oid00066';
?
Joe

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
   (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])