![]() This uses a correlated subquery which has the distinct advantage of working in SQL Server, MySQL, PostGres, etc. The above is valid syntax for SQL Server and all DBMS that have implemented CTEs. WHERE department.budget = max_budget.value You have SELECTMAX instead of SELECT MAX WITH max_budget(value) AS (SELECT MAX(budget) FROM department) check the manual that corresponds to your MySQL server version for the right syntax to use. Join over 16 million developers in solving code challenges on HackerRank, one of the best ways to prepare for programming interviews. This specific question suffers from two issues: The first and already addressed is that CTEs WITH don't exist in mysql. I tried to work with WITH in MySQL and encountered issues. This is the SQL Server version but I guarantee whatever logic you're attempting could be simplified if you explained what you were attempting to do versus "code doesn't work" Star 1 Code Issues Pull requests My HackerRank solutions. There’s multiple was you can attack this, but the most common way seems to be creation of a CTE, VIEW or function and using ROWNUMBER (), PARTITION () to help number and organize the rows. Another interesting query, with very unique criteria that you need to pay attention to. ![]() The test setter designs these questions to understand their candidates' level of database programming skills to store, modify, or retrieve data by writing efficient queries. Hackerrank SQL Advanced Select Occupations Solution. Note, these sql fiddles use the question that was a duplicate of this as it was at least more interesting to answer. In HackerRank Tests, Database (DB) Engineering questions assess the candidates' database querying knowledge in Microsoft SQL, MySQL, Oracle, or DB2 databases. To make this work with MySQL, you'll need to rewrite it as derived tables. WITH cte AS ( SELECT c.hackerid, h.name, COUNT(c. MySQL doesn't support Common Table Expressions (CTE) so either your mysql tag is incorrect or you've pulled this syntax from nowhere. Analytic functions greatly help with a question like this, so I will offer a solution using MySQL 8+, which, moving forward, will be the likely database which a reader of your question would be using (and HackerRank will at some point also be using MySQL 8+).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |