sql almost working

Tim Chase blinux.list at thechases.com
Tue May 6 23:07:50 UTC 2014


On May  6, 2014, Jude DaShiell wrote:
> [jude at athame ~]$ cat whealth.sql
> select round(avg(cys),1) as "Average Cystalic Pressure:" from
> health; select round(avg(dya),1) as "Average Dyastalic Pressure:"
> from health; select round(avg(pul),1) as "Average Pulse:" from
> health; select round(avg(sug),1) as "Average Sugar:" from health;

You can get the mode with a sub-query.  Additionally, you
can condense that SQL by putting them all in one query:

select
 round(avg(cys),1) as "Average Cystalic Pressure:",
 (select cys
  from health
  group by cys
  order by count(cys) desc, cys
  limit 1) as "Mode Cystalic Pressure:",
 round(avg(dya),1) as "Average Dyastalic Pressure:",
 (select dya
  from health
  group by dya
  order by count(dya) desc, dya
  limit 1) as "Mode Dyastalic Pressure:",
 round(avg(pul),1) as "Average Pulse:",
 (select pul
  from health
  group by pul
  order by count(pul) desc, pul
  limit 1) as "Mode Pulse:",
 round(avg(sug),1) as "Average Sugar:",
 (select sugar
  from health
  group by sugar
  order by count(sugar) desc, sugar
  limit 1) as "Mode Sugar:"
from health;

which should reduce the number of headers to just one, rather than
one for each query.  

I don't have your data to proof that query, but it should mostly be
what you want.

-tim







More information about the Blinux-list mailing list