Skip to content

Instantly share code, notes, and snippets.

@alaiacano
Last active January 2, 2016 15:58
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alaiacano/8326572 to your computer and use it in GitHub Desktop.
Save alaiacano/8326572 to your computer and use it in GitHub Desktop.
`p(x|z,y,t)`, untested
select numerator.x, numerator.num/denominator.denom, numerator.y, numerator.z, numerator.t
(select sum(x) as num, x, y, z, t from table group by x, y, z, t) numerator
join
(select sum(x) as denom, y, z, t from table group by y,z,t) denominator
on (numerator.y=denominator.y and numerator.z=denominator.z and numerator.t=denominator.t)
select numerator.x, numerator.num/denominator.denom
(select sum(x) as num, x from table where y=Y and z=Z and t=T group by x) numerator
cross join
(select sum(x) as denom from table where y=Y and z=Z and t=T) denominator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment