Senior
employee table | name | lang | | Nick | C# | | Nick | SQL | | Eva | Rust | | Vika | SQL | | Ivan | Java | | Ivan | SQL | You need to write a query that finds the names of employees who know SQL and at least one other language. select name from employee group by name having COUNT(DISTINCT lang) >= 2;
sobes.tech AI
Answer from AI
Your query is almost correct, but it does not guarantee that one of the languages is specifically SQL. To find the names of employees who know SQL and at least one other language, you need to add a condition that among the languages there is SQL, and the total number of languages is at least two.
Example query:
SELECT name
FROM employee
GROUP BY name
HAVING COUNT(DISTINCT lang) >= 2
AND SUM(CASE WHEN lang = 'SQL' THEN 1 ELSE 0 END) >= 1;
Here, COUNT(DISTINCT lang) >= 2 checks that the employee knows at least two languages, and SUM(CASE WHEN lang = 'SQL' THEN 1 ELSE 0 END) >= 1 ensures that among them there is SQL.