sql - Aggregate Relational Algebra (Maximum) -
i working on homework assignment requires selection occur pulls out element containing specific attribute of maximum value compared other records. i've read number of sources online reference "aggregate" relational algebra function called maximum, don't describe how works using basic operators. how 1 select attribute containing maximum value?
you can express aggregate functions basic operators. it's pretty neat thing.
suppose have table t, , we'd find maximum of "value" field. first, should take cartesian product of t -- or rather copy of itself, t2. select rows t.value smaller t2.value: nets unwanted rows, value less value of other row. maximal values, should subtract these unwanted rows set of rows. , that's it. @ least that's basic idea, need use projections dimensions right.
unfortunately have no idea how insert latex here, using relational algebra notation, it'd this:
π(t.a1...tan, t.value)(t) - π(t.a1...tan, t.value)( σ(t.value<t2.value)( ρ(t, t2) x t ) )
where π projection operator, - set difference, σ selection operator , ρ rename operator.
sqlishly:
select t.* t minus select t.* t, t t2 t.value<t2.value
and more practically:
select t.* t left join t t2 on t.value<t2.value t2.value null
of course, of academic interest, i.e. shows relational algebra works.
Comments
Post a Comment