Re: [SQL] calculating percentages

Поиск
Список
Период
Сортировка
От Thomas Good
Тема Re: [SQL] calculating percentages
Дата
Msg-id Pine.LNX.3.96.990712124625.8886A-100000@admin.nrnet.org
обсуждение исходный текст
Список pgsql-sql
On Mon, 12 Jul 1999, Rich Shepard wrote:

> > How does one do this:   SELECT (current_value/target) * 100;
> > in postgres?  
> 
> Tom,
> 
>   In postgres or anything else, I'd select the records I wanted first, then
> assign each percentage to a variable; e.g., 
> 
>     pct_chng = (current_value/target) * 100;
> 
> The varible, pct_chng, can be inserted in a view as another column and
> statistics can be calculated from these values.
> 
> Rich

Rich,

I believe you hit the nail on the head...it's Monday don't you know
and the brain wasn't plugged in.  I generally embed sql in perl and
can't imagine why it didn't occur to me to let perl's arithmetic 
operators do the work on the values returned from pg.

I do alot of one-off statement handles ($sth->$fetchrow_array) where 
the return value is an aggregate (so although the syntax is for a cursor
the stanza becomes a defacto singleton select).  Then I let perl 
do the rest, example (to suggest a startdate to a user):

$sth_timer = $dbh->prepare("
SELECT current_date - 30;
");
$sth_timer->execute or die;
$start_date = $sth_timer->fetchrow_array;
print("Start Date = $start_date? (Y/n): ");

Obviously, I'm an incurable shell scripter - but it does work!

Of course, I'll try the view you attached, and the function
another colleague sent but perl is probably what I'll use in the end.
Thanks for the wake up call!

Cheers,
Tom

------- North Richmond Community Mental Health Center -------

Thomas Good                                   MIS Coordinator
Vital Signs:                  tomg@ { admin | q8 } .nrnet.org                                         Phone:
718-354-5528                                          Fax:   718-354-5056                               
 
/* Member: Computer Professionals For Social Responsibility */ 



В списке pgsql-sql по дате отправления:

Предыдущее
От: Thomas Good
Дата:
Сообщение: Re: [SQL] calculating percentages
Следующее
От: Tom Lane
Дата:
Сообщение: Re: [SQL] calculating percentages