12 Appendix C Other Relational Query Languages account_number branch-name balance A-101 Downtown 500 A-215 Mianus 700 A-102 Perryridge 400 A-305 Round Hill 350 A-201 Perryridge 900 A-222 Redwood 700 A-217 Perryridge 750 Figure C.4 The account relation. The answer to the query is (A-217,750) To get the account number and balance of all accounts in relation vl,where the balance is greater than 800,we can write ?o1(A,B),B>800 The answer to this query is (A-201,900) In general,we need more than one rule to define a view relation.Each rule defines a set of tuples that the view relation must contain.The set of tuples in the view relation is then defined as the union of all these sets of tuples.The following Datalog program specifies the interest rates for accounts: interestrate(A,5):-account(A,N,B),B 10000 interestrate(A,6):-account(A,N,B),B>=10000 The program has two rules defining a view relation interest rate,whose attributes are the account number and the interest rate.The rules say that,if the balance is less than $10,000,then the interest rate is 5 percent,and if the balance is greater than or equal to $10,000,the interest rate is 6 percent. account_number balance A-201 900 A-217 750 Figure C.5 The 1 relation.12 Appendix C Other Relational Query Languages account_number branch_name balance A-101 Downtown 500 A-215 Mianus 700 A-102 Perryridge Perryridge Perryridge 400 A-305 Round Hill 350 A-201 900 A-222 Redwood 700 A-217 750 Figure C.4 The account relation. The answer to the query is (A-217, 750) To get the account number and balance of all accounts in relation v1, where the balance is greater than 800, we can write ? v1(A, B), B > 800 The answer to this query is (A-201, 900) In general, we need more than one rule to define a view relation. Each rule defines a set of tuples that the view relation must contain. The set of tuples in the view relation is then defined as the union of all these sets of tuples. The following Datalog program specifies the interest rates for accounts: interest rate(A, 5) :– account(A, N, B), B < 10000 interest rate(A, 6) :– account(A, N, B), B >= 10000 The program has two rules defining a view relation interest rate, whose attributes are the account number and the interest rate. The rules say that, if the balance is less than $10,000, then the interest rate is 5 percent, and if the balance is greater than or equal to $10,000, the interest rate is 6 percent. account_number balance A-201 900 A-217 750 Figure C.5 The v1 relation