sql - Finding the variance across columns for a single row in postgreSQL -
my database set this
customernumber bill_apr bill_mar bill_feb bill_jan
i need create new column has variance across monthly bills.
if can't this, need restructure database have multiple client numbers each month's bill different row? much rather set can calculate across columns.
i recommend restructure table 1 row per client per month. current structure, happens next year january? overwrite value? happens next month don't have column? add together column , update calculated column?
i recommend next structure:
create table bills (customernumber int, monthyear varchar(30), bill double, )
then, write view or query like
select customernumber, variance(bill) billvariance bills grouping customernumber
this homecoming statistical variance of bills each customer.
sql postgresql
No comments:
Post a Comment