Re: Calculate Percentage of Total Rows in Table?
Chayden Bates Wrote:
> I'm looking to calculate total rows of data by percentage.
The classic way:
USE test;
DROP TABLE IF EXISTS foo;
CREATE TABLE foo (c CHAR(1) NOT NULL);
INSERT INTO foo (c) VALUES ('1'), ('1'), ('2'), ('2'), ('3'), ('3'), ('3'), ('3'), ('3'), ('3');
SELECT
foo.c,
COUNT(*) * t.factor AS pct
FROM foo
JOIN (SELECT 100/COUNT(*) AS factor FROM foo) AS t
GROUP BY foo.c;
--
felix
Please use
BBCode to format your messages in this forum.
Subject
Written By
Posted
Re: Calculate Percentage of Total Rows in Table?
January 13, 2007 08:42AM
February 02, 2007 09:21PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.