Re: sql almost working

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On May  6, 2014, Jude DaShiell wrote:
> [jude@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




_______________________________________________
Blinux-list mailing list
Blinux-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/blinux-list




[Index of Archives]     [Linux Speakup]     [Fedora]     [Linux Kernel]     [Yosemite News]     [Big List of Linux Books]