Unix Technical Forum

Dividing two Count() Results

This is a discussion on Dividing two Count() Results within the SQL Server forums, part of the Microsoft SQL Server category; --> Just a quick question, how do I divide the results of these two queries together ? (select count (*) ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 06:58 PM
Robert
 
Posts: n/a
Default Dividing two Count() Results

Just a quick question, how do I divide the results of these two queries
together ?

(select count (*) as ontime from schedule where actualarrivaldate <=
estimatearrivaldate)

(select count (*) as total from schedule)


Thanks for any help
Robert


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 06:58 PM
David Portas
 
Posts: n/a
Default Re: Dividing two Count() Results

SELECT ontime, total, ontime/CAST(total AS REAL)
FROM
(SELECT COUNT(CASE WHEN actualarrivaldate <= estimatearrivaldate
THEN 1 END), COUNT(*)
FROM schedule) AS X(ontime,total)

(untested)

--
David Portas
------------
Please reply only to the newsgroup
--


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 06:58 PM
Robert
 
Posts: n/a
Default Re: Dividing two Count() Results

Thanks for the quick reply, the query worked perfect.
Cheers
Robert


"David Portas" <REMOVE_BEFORE_REPLYING_dportas@acm.org> wrote in message
news:nMadnd4h2ZNOrveiRVn-hw@giganews.com...
> SELECT ontime, total, ontime/CAST(total AS REAL)
> FROM
> (SELECT COUNT(CASE WHEN actualarrivaldate <= estimatearrivaldate
> THEN 1 END), COUNT(*)
> FROM schedule) AS X(ontime,total)
>
> (untested)
>
> --
> David Portas
> ------------
> Please reply only to the newsgroup
> --
>
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:08 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com