Subject | View output differs from straight SELECT output |
---|---|
Author | Reinier Olislagers |
Post date | 2012-10-23T12:03:21Z |
Hi list,
Firebird 2.5RC3 (Debian version) on Debian Squeeze
Trying to calculate percentages and totals (and hoping I'm getting the
expression right):
SELECT runs.id, count(rv.name),
((count(tr.resultvalue))*100)/(SELECT COUNT(resultvalue) FROM
testresults where testresults.testrun=runs.id)
from
testresults tr inner join
testruns runs on tr.TESTRUN=runs.id inner JOIN
resultvalues rv on tr.resultvalue=rv.id
group by runs.id, rv.name
having rv.name='OK'
gives output like
ID COUNT DIVIDE
8 5 50
(actually should mean for ID, there are 5 OKs which are 50% of the total
results)
I created a view with this SQL:
CREATE VIEW OKRESULTS (RUNID, OKCOUNT, OKPERCENTAGE)
AS
SELECT runs.id, count(rv.name),
((count(tr.resultvalue))*100)/(SELECT COUNT(resultvalue) FROM
testresults where testresults.testrun=runs.id)
from
testresults tr inner join
testruns runs on tr.TESTRUN=runs.id inner JOIN
resultvalues rv on tr.resultvalue=rv.id
group by runs.id, rv.name
having rv.name='OK';
which gives output (in FlameRobin) like:
RUNID OKCOUNT OKPERCENTAGE
8 5 [null]
What am I doing wrong? Do I need to explicitly CAST the expression to
e.g. a float?
Thanks,
Reinier
Firebird 2.5RC3 (Debian version) on Debian Squeeze
Trying to calculate percentages and totals (and hoping I'm getting the
expression right):
SELECT runs.id, count(rv.name),
((count(tr.resultvalue))*100)/(SELECT COUNT(resultvalue) FROM
testresults where testresults.testrun=runs.id)
from
testresults tr inner join
testruns runs on tr.TESTRUN=runs.id inner JOIN
resultvalues rv on tr.resultvalue=rv.id
group by runs.id, rv.name
having rv.name='OK'
gives output like
ID COUNT DIVIDE
8 5 50
(actually should mean for ID, there are 5 OKs which are 50% of the total
results)
I created a view with this SQL:
CREATE VIEW OKRESULTS (RUNID, OKCOUNT, OKPERCENTAGE)
AS
SELECT runs.id, count(rv.name),
((count(tr.resultvalue))*100)/(SELECT COUNT(resultvalue) FROM
testresults where testresults.testrun=runs.id)
from
testresults tr inner join
testruns runs on tr.TESTRUN=runs.id inner JOIN
resultvalues rv on tr.resultvalue=rv.id
group by runs.id, rv.name
having rv.name='OK';
which gives output (in FlameRobin) like:
RUNID OKCOUNT OKPERCENTAGE
8 5 [null]
What am I doing wrong? Do I need to explicitly CAST the expression to
e.g. a float?
Thanks,
Reinier