Groups | Blog | Home
all groups > sql server mseq > august 2005 >

sql server mseq : Query help !


Ronny de Jong
8/12/2005 1:30:02 AM
Dear all,

I'd like to display the result of this query in percentage:

SELECT SYS.Client_Version0, SYS.Client_Type0, count(*) as 'Count'
FROM v_R_System as SYS
WHERE SYS.Client0=1
group by SYS.Client_Version0, SYS.Client_Type0
order by SYS.Client_Version0, SYS.Client_Type0

Any idea's how,

I appreciate your help....
Vishal Parkar
8/12/2005 8:05:11 AM
try:

SELECT SYS.Client_Version0, SYS.Client_Type0, count(*) as 'Count',
(count(*)* cast(100 as decimal) / cnt) 'pct'
FROM v_R_System as SYS ,
(select count(*) 'cnt' from v_R_System) b
WHERE SYS.Client0=1
group by SYS.Client_Version0, SYS.Client_Type0,cnt
order by SYS.Client_Version0, SYS.Client_Type0

--Vishal

[quoted text, click to view]
Hugo Kornelis
8/12/2005 9:38:33 PM
[quoted text, click to view]

Hi Ronny,

SELECT SYS.Client_Version0, SYS.Client_Type0, count(*) as 'Count',
count(*) * 100.0 / (select count(*) from v_R_System) as 'Percent'
FROM v_R_System as SYS
WHERE SYS.Client0=1
group by SYS.Client_Version0, SYS.Client_Type0
order by SYS.Client_Version0, SYS.Client_Type0

(untested)

Best, Hugo
--

Amit Jain
8/16/2005 9:49:01 PM
Hello Ronny,

Pls clarify the %age against the
- total records count in table or
- Total records counts in SYS.Client_Version0
As you are using 2 columns in your select query

For first case solution is already provided.
But for secound case , find the query

SELECT SYS.Client_Version0,
SYS.Client_Type0, ((count(*) * 100)/( SELECT count(*) FROM v_R_System as
Sub_SYS WHERE SYS.Client0=1 and Sub_SYS.Client_Version0 =
SYS.Client_Version0)) as 'Percentage'
FROM v_R_System as SYS
WHERE SYS.Client0=1
group by SYS.Client_Version0, SYS.Client_Type0
order by SYS.Client_Version0, SYS.Client_Type0

(Untested)



[quoted text, click to view]
AddThis Social Bookmark Button