## Section 1 Implement basic SQL-like operations, such as select, where, join, e

## Section 1
Implement basic SQL-like operations, such as select, where, join, etc., of an in-memory database.
## Instructions
Assume the following data is stored in the in-memory database
**departments**
| id  |  name       |
| —-|————-|
| 0   | engineering |
| 1   | finance     |
**users**
| id | department_id | name   |
| —|—————|——–|
| 0  |  0            |  Ian   |
| 1  |  0            |  John  |
| 2  |  1            |  Eddie |
| 3  |  1            |  Mark  |
**salaries**
| id | user_id  | amount |
| —|———-|——–|
| 0  | 0        | 100    |
| 1  | 1        | 150    |
| 2  | 1        | 200    |
| 3  | 3        | 200    |
| 4  | 3        | 300    |
| 5  | 4        | 400    |
### First step
Please implement `select` and `where` in `Table` class. For the sake of simplicity, you can assume all operations will be passed valid parameters. You do not need to concern yourself with error handling for occurrences like selecting an arbitrary column from a non-existent table.
For example,
~~~python
# Should print something like
# id, department_id, name
# 1, 0, John
print(db.table(‘users’)
.where(‘id’, 1)
.select([‘id’, ‘department_id’, ‘name’]))
~~~
### Second step
Please implement `inner_join` in `Database` class.
~~~python
# Should print something like
# users.name, departments.name
# Ian, engineering
# John, engineering
print(db.inner_join(db.table(‘users’), ‘department_id’, db.table(‘departments’), ‘id’)
.where(‘departments.name’, ‘engineering’)
.select([‘users.name’, ‘departments.name’]))
~~~
### Third step
Please implement `left_join`, `right_join` and `outer_join` in `Database` class.
~~~python
# Should print something like
# users.name, salaries.amount
# Ian, 100
# John, 150
# John, 200
# Mark, 200
# Mark, 300
# Eddie, None
print(db.left_join(db.table(‘users’), ‘id’, db.table(‘salaries’), ‘user_id’)
.select([‘users.name’, ‘salaries.amount’]))
# Should print something like
# users.name, salaries.amount
# Ian, 100
# John, 150
# John, 200
# Mark, 200
# Mark, 300
# None, 400
print(db.right_join(db.table(‘users’), ‘id’, db.table(‘salaries’), ‘user_id’)
.select([‘users.name’, ‘salaries.amount’]))
# should print something like
# users.name, salaries.amount
# Ian, 100
# John, 150
# John, 200
# Mark, 200
# Mark, 300
# Eddie, None
# None, 400
print(db.outer_join(db.table(‘users’), ‘id’, db.table(‘salaries’), ‘user_id’)
.select([‘users.name’, ‘salaries.amount’]))
~~~

The post ## Section 1
Implement basic SQL-like operations, such as select, where, join, e appeared first on Assignmentio.

GET HELP WITH YOUR HOMEWORK PAPERS @ 25% OFF

For faster services, inquiry about  new assignments submission or  follow ups on your assignments please text us/call us on +1 (251) 265-5102

Write My Paper Button

WeCreativez WhatsApp Support
We are here to answer your questions. Ask us anything!
👋 Hi, how can I help?
Scroll to Top