Q
Q
QA Engineer2021-03-30 18:23:57
SQL
QA Engineer, 2021-03-30 18:23:57

Why are my SQL queries wrong?

Assignment data below

You are testing a service that delivers food in 30 minutes. While this is a small startup, so you work with only four tables:

Orders - all delivered orders;
ORDERS_ID — order IDs, int;
USER_ID — user IDs, int;
EMPLOYEE_ID — employee ID, int;
DELIVERY_TIME — delivery time in minutes, int;
ITEMS — list of goods, char;

Users - users;
USER_ID — user IDs, int;
FULL_NAME — user's full name, char;
PHONE — user's phone number, char;
ADDRESS - user address, char;

Employees - employees;
EMPLOYEE_ID — employee ID, int;
FIRST_NAME — employee name, char;
LAST_NAME — employee last name, char;
PHONE — employee phone, char;
JOB_ID — specialization ID, int;

Jobs — job types in the service
JOB_ID — specialization ID, int;
JOB_TYPE - specialization type, char;
HOURS — number of working hours per week, int;
SALARY — salary of an employee with this specialization in rubles, int;

60634423972ac465697825.jpeg

================================================= ==============================================
1 - TASK
The support service received a lot of complaints: orders containing buckwheat are delivered in almost an hour, although the service promises to be in time in 30 minutes.

Check if the couriers are really late. Select all orders where there is at least one product - "buckwheat" and delivery time over 30 minutes. The resulting table should contain order IDs and couriers IDs.

My answer is:

SELECT
ORDERS_ID,
EMPLOYEE_ID


FROM
orders

WHERE
ORDERS_ID = 'buckwheat' AND DELIVERY_TIME > 30;
================================================= ================================================= ===
2 - TASK
The manager offered to add a new functionality to the product: monitoring, which shows the most active customers for the entire time the company has been working.

Check that the list of users is displayed correctly on the screen. At this stage of development, it is enough to check only the client IDs.

Choose the five most active customers by the number of orders.

In the resulting table, display the ID of each user and the number of orders.

Sort the data in descending order by the number of orders, select the five most active customers.

Please include an SQL query in your answer.

MY ANSWER:

SELECT
Users.USER_ID,
COUNT(Orders.ORDERS_ID) as orders_id

FROM Users
INNER JOIN Orders ON Orders.ORDERS_ID = Users.USER_ID

ORDER BY (orders_id) DESC

LIMIT 5

============ ================================================= ====================================
3 - TASK A
bug-report came from the accounting department: the salaries of employees are calculated incorrectly. It turned out that almost all the errors in the calculations are in the pay sheets of managers.

Output a list of IDs of all employees whose specialization contains "manager", with a salary of more than 70,000 rubles.

Please include an SQL query in your answer.

My answer is:

SELECT
Employees.EMPLOYEE_ID

FROM Employees
INNER JOIN Jobs ON Jobs.SALARY = Employees.EMPLOYEE_ID

WHERE EMPLOYEE_ID = 'manager' AND SALARY > 70,000

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vitsliputsli, 2021-03-30
@QA Engineer

1. You write ORDERS_ID = 'buckwheat', according to the TK "ORDERS_ID — order IDs, int;"
2. You write Orders.ORDERS_ID = Users.USER_ID, according to the TK "ORDERS_ID - order IDs, int; USER_ID - user IDs, int;", i.e. completely different things, it makes no sense to join tables on them.
3. You write EMPLOYEE_ID = 'manager', according to the TOR "EMPLOYEE_ID — employee ID, int;"
Understand what an ID is in a database, how relationships are created. Create a database according to the specified conditions, and make attempts on it.

L
Lazy @BojackHorseman, 2021-03-30
SQL

because you don't know sql.
you don't even know how to spell "not" correctly with different parts of speech.

B
BorLaze, 2021-03-30
@BorLaze

Why are my SQL queries wrong?

Because there are no SQL queries.
Here is a hodgepodge of SQL function words and table fields, put together without the slightest understanding of the essence.
ORDERS_ID = 'гречка'
Orders.ORDERS_ID = Users.USER_ID
Jobs.SALARY = Employees.EMPLOYEE_ID

Really, what could be wrong here?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question