We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
/*This solution works for any of the listed RDBMS:DB2, mySQL, Oracle, SQL Server.*/SELECTAVG(population)FROMcityWHEREdistrict='California';
Anyhow there are discrepancies in the values displayed for DB2, mySQL and SQL Server.
When compared to the expected result shown, while the solution run under Oracle shows the exact decimal precision, mySQL shows more digits after the decimal point and DB2 and SQL Server show only the integer part of the average value. Anyhow the interpreter considers the solution correct for any of the RDBMSs.
/* DB2 solution to meet exact decimal precision */SELECTCAST(AVG(population)ASDECIMAL(6,3))FROMcityWHEREdistrict='California';/*Your code did not pass this test case.Your Output (stdout)SQL0413N Overflow occurred during numeric data type conversion. SQLSTATE=22003 Expected Output113000.667Compiler MessageRuntime Error*/
Can you guys tell me anyworkaround to get the results I want and if there is anything or any specific limit in the challenge environment?
All the best!
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Revising Aggregations - Averages
You are viewing a single comment's thread. Return to all comments →
Anyhow there are discrepancies in the values displayed for DB2, mySQL and SQL Server.
When compared to the expected result shown, while the solution run under Oracle shows the exact decimal precision, mySQL shows more digits after the decimal point and DB2 and SQL Server show only the integer part of the average value. Anyhow the interpreter considers the solution correct for any of the RDBMSs.
Trying to meet the exact value expected when running the script under DB2, I tested a CAST() solution proposed at this website: https://www.w3resource.com/sql/aggregate-functions/avg-decimal-places-using-cast-within-avg.php, but got a runtime error:
Can you guys tell me anyworkaround to get the results I want and if there is anything or any specific limit in the challenge environment?
All the best!