Spaces:
Runtime error
Runtime error
Test SQL
#10
by
helleuch
- opened
Given the following tables:
Table "public.employees"
Column | Type | Collation | Nullable | Default
-------------+------------------------+-----------+----------+---------
id | integer | | not null | nextval('employees_id_seq'::regclass)
first_name | character varying(50) | | not null |
last_name | character varying(50) | | not null |
department | character varying(50) | | |
Indexes:
"employees_pkey" PRIMARY KEY, btree (id)
+------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------+------+-----+---------+----------------+
| id | int | NO | PRI | NULL | auto_increment |
| employee_id| int | YES | MUL | NULL | |
| day_off | date | NO | | NULL | |
+------------+---------+------+-----+---------+----------------+
+---------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+---------+------+-----+---------+----------------+
| id | int | NO | PRI | NULL | auto_increment |
| employee_id | int | YES | MUL | NULL | |
| amount | int | NO | | NULL | |
| effective_date| date | YES | | NULL | |
+---------------+---------+------+-----+---------+----------------+
Give me the employees with a salary greater than 10k
🤖: To retrieve the employees with a salary greater than 10k, you can use a SQL query like this:
SELECT e.first_name, e.last_name, e.department, s.amount
FROM employees e
JOIN salaries s ON e.id = s.employee_id
WHERE s.amount > 10000;
This query joins the employees
table with the salaries
table on the employee_id
column, and then filters the results to only include employees with a salary greater than 10k.
Note that the amount
column in the salaries
table is an integer, so the comparison is done in integer arithmetic. If you want to compare the salary in a different currency, you will need to convert the amount to the appropriate currency before comparing it to the threshold.
Declare a class in Python