Reputation: 33
I'm trying to create a query. I have two tables
customer
(customer_id
)rental
(rental_date
(timestamp), customer_id
)SELECT to_char( rental_date, 'Month') AS month,
(count(Distinct customer.customer_id)/
(count (distinct rental.customer_id) * 100)
) AS percentage
FROM RENTAL,customer
GROUP BY month;
But the result is zero.
Upvotes: 2
Views: 5325
Reputation: 7310
When all "numbers" involved in an operation are integers, the result will be an integer too.
Try this way:
SELECT
to_char( rental_date, 'Month') AS month,
(
count(distinct customer.customer_id)::float /
(count(distinct rental.customer_id)::float * 100::float)
)
as percentage
FROM
RENTAL,customer
GROUP BY month;
Upvotes: 4