'Athena count/Sum column divided by count/Sum column returns zero
I am trying to find percentage based on id column.
issue - I am trying to use count(column)/select count(column) from table which is giving output as 'Zero'
Table name - abc
When I use count function to achieve it is returning zero.
This below percentage query always returns zero, tried with many logic.
SELECT Count(id) id,
CASE
WHEN Cast(tax AS DOUBLE) BETWEEN 7.99 AND 9.99 THEN 'test'
WHEN Cast(tax AS DOUBLE) BETWEEN 10.00 AND 19.99 THEN 'test1'
WHEN Cast(tax AS DOUBLE) BETWEEN 20.00 AND 43.69 THEN 'test3'
ELSE '#N/A'
END AS "product_category",
FROM abc
WHERE Cast(tax AS DOUBLE) BETWEEN 10.00 AND 19.99
AND id IN
(
SELECT id
FROM abc
WHERE cast(tax double) BETWEEN 7.99 AND 9.99) )SELECT Count(id)/
(
SELECT Count(b.id)
FROM abc
WHERE Cast(tax AS DOUBLE) BETWEEN 7.99 AND 9.99)
FROM abc
if tax between 0 and 10 it is 'test1' 11 and 20 it is 'test2' 21 and 30 it is ;test3'
I am trying to find a output like below
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|