How can I find MAX with relational algebra?

前端 未结 7 1144
庸人自扰
庸人自扰 2020-11-27 11:44

Working with databases, how can I find MAX using relational algebra?

7条回答
  •  青春惊慌失措
    2020-11-27 12:20

    lets think we have a relation with an attribute A and values 1,2,3

    A
    
    1
    2
    3
    

    so now..

    project A values and rename with A1

    A1
    1
    2
    3
    

    again project A values and rename with A2

    A2
    1
    2
    3
    

    join this with A2 i.e \join_{A2
    so the - Output schema: (A2 integer, A1 integer)

    A2

    hear always A2 values will be less than A1 because we join like that(a2)

    now project A2 the output is like below

    A2
    1
    2
    

    now diff with original attribute

    A diff A2
    

    A
    1
    2
    3
    

     diff
    

    A2
    1
    2
    

    Output is 3 maximum value

提交回复
热议问题