SQL where clause two seperate values? [closed] - mysql

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
so for an assignment I need to Find the manager(s) of the employee(s) who support customer(s) from Canada from the chinook data base
For now I have the following code:
select distinct employee.LastName, employee.EmployeeId, employee.ReportsTo
from customer,
employee
where customer.Country = 'Canada'
and customer.SupportRepId = employee.EmployeeId;
So I get the following results
So I need to get the names of the general manager whose EmployeeId is 2, but I don't know how to put it into one query.
This is an overview of all the employees:
This is an overview of all the customers:

You have to join the the employee table twice:
select distinct employee.LastName, employee.EmployeeId, manager.Lastname
from
customer
join employee as employee on customer.SupportRepId = employee.EmployeeId
join employee as manager on employee.ReportsTo = manager.employeeId
where customer.Country = 'Canada'

Related

sql - mysql - tables [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed yesterday.
Improve this question
I need to collect the name and total order of customers who had an order of more than 56000. there are three tables, customers, orders, and orderdetails.
This is the output that I need:
this is the code that im trying:
select a.customername, sum(c.priceeach*c.quantityordered) as "ORDERTOTAL"
from customers a
join orders b on b.customernumber = a.customernumber
join orderdetails c on c.ordernumber = b.ordernumber
having sum(c.priceeach*c.quantityordered) > 58000
group by a.customername;
but it is giving me 76 rows.
when I only try with the table order details i can get exact 7 rows but the table orderdetails doesnt contain customername, I can't undrestand where am I doing it wrong.

Updating a column with a Count of data from another column in the same table? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
As the title suggests, trying to take the count or possibly distinct count of a column, we call it year, to count the number of a years for an individual or populated ID and place it another column in the same table. Here is an idea of what I have so far and we want to update the table. Thank you.
Join group table to updated table directly:
UPDATE outputtable O JOIN
(SELECT personID, COUNT(DISTINCT year) AS countYear
FROM outputtable GROUP BY personID) temp ON O.personID=temp.personID
SET O.N=temp.countYear

SQL Condition with two tables [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have this task:
Write a single query to display the fname and lname of employees whose salary is higher than $5000.
The problem is that there is 2 tables and fname and lname is from the table "employee" and salary is from the table "Job". How do I make this condition work?
I can only write this query, but I don't know how to write the fact that salary is in another table.
SELECT fname, lname FROM employee WHERE fixed_salary > 5000;
Please, help and thank you! :)
SELECT fname, lname FROM employee
INNER JOIN Job ON employee.job_id=job.job_id
WHERE fixed_salary > 5000;
basic SQL joining, read something about e.g. here:
https://dev.mysql.com/doc/refman/8.0/en/join.html
SELECT
e.fname,
e.lname,
j.fixed_salary
FROM employee e
INNER JOIN Job j ON j.id = e.job_id
WHERE j.fixed_salary > 5000;

SQL query join or subquery [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
[![table named teams and Matches ][2]][2]I have 2 tables
[2]: https://i.stack.imgur.com/7v4nT.png**strong text**
I need data from these 2 tables in such a ways that a new table is formed with the following data
mid, result, date, team1id, team2id from matches table on the basis of tourid=6 and from table of team i need to show the Tname as team1 and Tname as team2.
Sounds like you need a join:
select matches.*,t1.Tname as team1,t2.Tname as team2 from matches
join team t1 on t1.Teamid=matches.team1id
join team t2 on t2.Teamid=matches.team2id
where tourid=6

selecting from table twice PHP SQL [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
i have a big problem and cant solve that:
i have a table (action) that store two id belong users in each row. one for customers and one for service providers.
name and family of these users are in another table (tablesite) that can be fetch. but i do not know how i can fetch either name and family of customers and also name of family of service_providers .
result should be like this:
example: first line service_provider_id is 33 and customer_id is 34
so i need this:
service_provider: sajad khammar --- customer: akbar ahmadi
SELECT
a.job_id,
CONCAT( s.name, ' ', s.family ) AS service_provider,
CONCAT( c.name, ' ', c.family ) AS customer
FROM action a
INNER JOIN tablesite s
ON a.service_provider = s.id_user
INNER JOIN tablesite c
ON a.customer_id = c.id_user