Question
sql question

5. Find out who keep(s) the highest balance among all clients associated with bookkeeper 24 (Hint: you may recall one of the
Tables BOOKKEEPER CLIENT - BKP_NUM . Click to Add. CLT_BALANCE - $315,50 22 $525.00 24 $229.50 24 $0.00 24 CUENT CLT_B - CLT_
0 0
Add a comment Improve this question Transcribed image text
Answer #1

5.

CREATE VIEW [Q5] AS
SELECT * FROM CLIENT

WHERE BKP_NUM=24 AND

CLI_BALANCE = (SELECT MAX(CLI_BALANCE) FROM CLIENT) ;

EXPLANATION:-

Here, we are creating view with name Q5.

Here we are using SELECT * statement to fetch the data with all the columns from the table CLIENT.

For filtering this data we used WHERE clause in which we checked for BKP_NUM=24 and whether the balance of client is equal to the highest balance which is fetched using MAX() aggregate function.

This query can give multiple records which are having bkp_num as 24v and maximum balance.

6.

a)UPDATE CLIENT

SET CLI_BALANCE = 525

WHERE CLI_NAME='Afton Mills' ;

EXPLANATION:-

Here we used UPDATE to update CLI_BALANCE which are having CLI_NAME as Afton Mills by using WHERE Clause.

b)No , it won't change the result of Q5 as the record with CLI_ NAME as Afton Mills is associated with BKP_NUM 22 ,while in 5 it was for BKP_NUM 24 .

c)SELECT CLI_BALANCE FROM CLIENT

WHERE CLI_NAME ='Afton Mills' ;

EXPLANATION:-

It uses select to fetch data of balance from the CLIENT table and  WHERE clause is used to fulter the data.

d) ROLLBACK

EXPLANATION:-

Any uncommitted change pf UPDATE query can be restored to earlier state by using ROLLBACK command.'

e)

SELECT CLI_BALANCE FROM CLIENT

WHERE CLI_NAME ='Afton Mills' ;

7. SELECT BKP_NUM,SUM(CLI_BALANCE) AS Total_Balance FROM

CLIENT GROUP BY BKP_NUM ;

EXPLANATION:-

Above query uses SELECT statement along with SUM() aggregate function on CLI_BALANCE to get sum for each BKP_NUM.

Here, GROUP BY is used along with aggregate function SUM() to get Sum for balance for each group divided on the basis on BKP_NUM.

8. SELECT CLI_NAME ,BKP_NUM ,CONCAT(BKP_FNAME ,' ',BKP_LNAME) AS BKP_NAME

FROM CLIENT NATURAL JOIN BOOKKEEPER

ORDER BY BKP_NUM DESC;

EXPLANATION:-

Here, again we are using SELECT to fetch the data , then for getting full name we used CONCAT() function to combine first and last name and name it as BKP_NAME using AS keyword.

Then , for natural join we used NATURAL JOIN keyword between two table .

Then for ordering with BKP_NUM we used ORDER BY clause along with DESC keyword to get ordering in descending order.

Add a comment
Know the answer?
Add Answer to:
sql question 5. Find out who keep(s) the highest balance among all clients associated with bookkeeper...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT