1179. Reformat Department Table

Tutd Schema:

data Month = Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec;
department := relation{ id Integer, revenue Integer, month Month}{
 tuple{id 1, revenue 8000,  month Jan},
 tuple{id 2, revenue 9000,  month Jan},
 tuple{id 3, revenue 10000,  month Feb},
 tuple{id 1, revenue 7000,  month Feb},
 tuple{id 1, revenue 6000,  month Mar}};
key department_ukey {id, month} department;

Thinking Process:

-- if I don't want to see Nothing/null all over around...

department group ({all but month}) as departmentRevenue)

-- if I need Nothing to make the statement more clear...I've found a way to do that on LeetCode 175. Combine Two Tables. It involves cross product, not matching, extend Nothings, add Justs. But maybe a case expression can simplify it.  

-- :{ tmp := case @atom isIn set of true -> Just atom; false -> Nothing

-- or an operation a _add_Just_if_they_can_join_and_add_Nothing_while_they_cannot_ b

answer := (((department where month=Jan){all but month} rename {revenue as jan}) this_op department{id}) join ...


-- maybe an operator is useful for oberservation: a _either_of_them_ b == {attributes intersects but atoms unioned}.  It shows truth about attributes intersected in either one of them.

留言

這個網誌中的熱門文章

185. Department Top Three Salaries