Write all the sql code (including create, insert and select)

A Guide to SQL
9th Edition
ISBN:9781111527273
Author:Philip J. Pratt
Publisher:Philip J. Pratt
Chapter7: Database Administration
Section: Chapter Questions
Problem 4SCG: Write, but do not execute, the commands to grant the following privileges: a. User Oliver must be...
icon
Related questions
Question

Write all the sql code (including create, insert and select)

Create the following tables in your database with the following schema:
Table: Users
I Column Name
| Type
+--
int
I account
| name
| varchar
+--
---+
-----
account is the primary key for this table.
Each row of this table contains the account number of each user in the bank.
Table: Transactions
| Column Name
| Туре
+-
| trans id
I account
| amount
| transacted_on | date
| int
| int
| int
+--
trans id is the primary key for this table.
Each row of this table contains all changes made to all accounts.
amount is positive if the user received money and negative if they
transferred money.
All accounts start with a balance of 0.
Add the following data to your tables:
Input:
Users table:
+---
I account
I name
+---
| 900001
| 900002
| 900003
| Alice
| Bob
| Charlie
Transactions table:
+--
| trans id
| account
| amount
| transacted_on
+---
| 1
| 2
| 3
| 900001
| 900001
| 900001
I 900002
| 900003
| 900003
| 900003
| 7000
I 7000
| -3000
| 1000
| 6000
| 6000
| -4000
2020-08-01
2020-09-01
2020-09-02
2020-09-12
5
2020-08-07
2020-09-07
| 7
2020-09-11
+--
Transcribed Image Text:Create the following tables in your database with the following schema: Table: Users I Column Name | Type +-- int I account | name | varchar +-- ---+ ----- account is the primary key for this table. Each row of this table contains the account number of each user in the bank. Table: Transactions | Column Name | Туре +- | trans id I account | amount | transacted_on | date | int | int | int +-- trans id is the primary key for this table. Each row of this table contains all changes made to all accounts. amount is positive if the user received money and negative if they transferred money. All accounts start with a balance of 0. Add the following data to your tables: Input: Users table: +--- I account I name +--- | 900001 | 900002 | 900003 | Alice | Bob | Charlie Transactions table: +-- | trans id | account | amount | transacted_on +--- | 1 | 2 | 3 | 900001 | 900001 | 900001 I 900002 | 900003 | 900003 | 900003 | 7000 I 7000 | -3000 | 1000 | 6000 | 6000 | -4000 2020-08-01 2020-09-01 2020-09-02 2020-09-12 5 2020-08-07 2020-09-07 | 7 2020-09-11 +--
Write an SQL query to report the name and balance of users with a balance higher than 10000. The
balance of an account is equal to the sum of the amounts of all transactions involving that account.
Return the result table in any order.
The results should be:
Output:
I name
balance
| Alice
11000
Explanation:
Alice's balance is (7000 + 7000 -
Bob's balance is 1000.
3000) = 11000.
Charlie's balance is (6000 + 6000
4000) = 8000.
Transcribed Image Text:Write an SQL query to report the name and balance of users with a balance higher than 10000. The balance of an account is equal to the sum of the amounts of all transactions involving that account. Return the result table in any order. The results should be: Output: I name balance | Alice 11000 Explanation: Alice's balance is (7000 + 7000 - Bob's balance is 1000. 3000) = 11000. Charlie's balance is (6000 + 6000 4000) = 8000.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Multiple table
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
A Guide to SQL
A Guide to SQL
Computer Science
ISBN:
9781111527273
Author:
Philip J. Pratt
Publisher:
Course Technology Ptr
Oracle 12c: SQL
Oracle 12c: SQL
Computer Science
ISBN:
9781305251038
Author:
Joan Casteel
Publisher:
Cengage Learning
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning