I'm trying to get the percentage of german customers inside the customers table here: https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_all
I'm using this query:
SELECT cast((cast((SELECT COUNT(*) FROM Customers WHERE Country = "Germany") as DECIMAL(5,2))/cast((SELECT COUNT(*) FROM Customers) as DECIMAL(5,2))) AS DECIMAL(5,2)) AS PercentageGermans;
For some reason, I still get 0 returned, despite casting all the constituents of the termin to decimal 5,2.
I already searched SO on the topic and found this answer: https://stackoverflow.com/a/26537471/8732285
Here, the casting I'm trying to do is done pretty much the same way I do:
cast((select count(random_int) from test) as decimal(7,2))
The cast is being applied to the full subquery. There it works, which can be seen on the fiddle as well: http://sqlfiddle.com/#!15/63252/37
But I don't understand what's going wrong in my case.