Subject | Using aliases in the same select clause |
---|---|
Author | Gerhardus Geldenhuis |
Post date | 2002-10-30T09:33Z |
Hi
I have the following query:
select
ra.reasonsforrejection,
(
select count(darno)
from repairauthorisation
where AUTHORISED = '0'
)as CountPerReason,
count(ra.darno)as NumberofRejections
from repairauthorisation ra
where ra.AUTHORISED = '0'
group by ra.reasonsforrejection
Is there a way to add the following as a field:
(NumberofRejections*100/CountPerReason) as PercentageValue
using the alias names. Logically one would be able to...
The only way I could figure out is to do the following but it looks
monstrous and is difficult to figure out what it does.
cast((count(ra.darno))*100/(select count(darno) from
repairauthorisation where AUTHORISED = '0')as varchar(4))||'%'
The query at the moment looks like this which does not look very
elegant. It works however...
select
ra.reasonsforrejection,
(
select count(darno)
from repairauthorisation
where AUTHORISED = '0' and
(ra.AUTHORISEDDATE between :StartDate and :EndDate)
)as CountPerReason,
count(ra.darno)as NumberofRejections,
(
cast((count(ra.darno))*100/
(
select count(darno)
from repairauthorisation
where AUTHORISED = '0' and
(ra.AUTHORISEDDATE between :StartDate and :EndDate))as
varchar(4))||'%'
)as Percentage
from repairauthorisation ra
where ra.AUTHORISED = '0' and
(ra.AUTHORISEDDATE between :StartDate and :EndDate)
group by ra.reasonsforrejection
Groete
Gerhardus
I have the following query:
select
ra.reasonsforrejection,
(
select count(darno)
from repairauthorisation
where AUTHORISED = '0'
)as CountPerReason,
count(ra.darno)as NumberofRejections
from repairauthorisation ra
where ra.AUTHORISED = '0'
group by ra.reasonsforrejection
Is there a way to add the following as a field:
(NumberofRejections*100/CountPerReason) as PercentageValue
using the alias names. Logically one would be able to...
The only way I could figure out is to do the following but it looks
monstrous and is difficult to figure out what it does.
cast((count(ra.darno))*100/(select count(darno) from
repairauthorisation where AUTHORISED = '0')as varchar(4))||'%'
The query at the moment looks like this which does not look very
elegant. It works however...
select
ra.reasonsforrejection,
(
select count(darno)
from repairauthorisation
where AUTHORISED = '0' and
(ra.AUTHORISEDDATE between :StartDate and :EndDate)
)as CountPerReason,
count(ra.darno)as NumberofRejections,
(
cast((count(ra.darno))*100/
(
select count(darno)
from repairauthorisation
where AUTHORISED = '0' and
(ra.AUTHORISEDDATE between :StartDate and :EndDate))as
varchar(4))||'%'
)as Percentage
from repairauthorisation ra
where ra.AUTHORISED = '0' and
(ra.AUTHORISEDDATE between :StartDate and :EndDate)
group by ra.reasonsforrejection
Groete
Gerhardus