HI,
I'm using a CASE statment to count values in a column. a sample is..
Rowdate Trunk DNIS
2007071604 6 30003
2007071604 5 30003
2007071604 4 30003
I have created the following query which works correctly..
SELECT RowDate, DNIS
SUM(CASE
WHEN trunk = 4 THEN 1
ELSE 0
END) trunk_4_Total,
SUM(CASE
WHEN trunk = 5 THEN 1
ELSE 0
END) trunk_5_Total,
SUM(CASE
WHEN trunk = 6 THEN 1
ELSE 0
END) trunk_6_Total,
count(*) as Total_Calls,
FROM TrunkHistory
where sourceid = 1
and RowDate between 2007071604 and 2007071605
and Trunk in (4, 5, 6)
and DNIS = 30003
group by DNIS, RowDate
order by DNIS, RowDate asc
However i now need to know what the percentage of each value is in relation to the total. IE..
((trunk_4_Total / (trunk_4_Total + trunk_5_Total + trunk_6_Total)) * 100)
But I'm not sure how to work the syntax into the query.
Any help is appreciated, Thanks in advance!
VLG711
I'm using a CASE statment to count values in a column. a sample is..
Rowdate Trunk DNIS
2007071604 6 30003
2007071604 5 30003
2007071604 4 30003
I have created the following query which works correctly..
SELECT RowDate, DNIS
SUM(CASE
WHEN trunk = 4 THEN 1
ELSE 0
END) trunk_4_Total,
SUM(CASE
WHEN trunk = 5 THEN 1
ELSE 0
END) trunk_5_Total,
SUM(CASE
WHEN trunk = 6 THEN 1
ELSE 0
END) trunk_6_Total,
count(*) as Total_Calls,
FROM TrunkHistory
where sourceid = 1
and RowDate between 2007071604 and 2007071605
and Trunk in (4, 5, 6)
and DNIS = 30003
group by DNIS, RowDate
order by DNIS, RowDate asc
However i now need to know what the percentage of each value is in relation to the total. IE..
((trunk_4_Total / (trunk_4_Total + trunk_5_Total + trunk_6_Total)) * 100)
But I'm not sure how to work the syntax into the query.
Any help is appreciated, Thanks in advance!
VLG711