You are here: Re: show number of values as % of total records..? « MsSQL Server « IT news, forums, messages
Re: show number of values as % of total records..?

Posted by Erland Sommarskog on 02/15/07 22:26

Otto (ottoleholt@tele.dk) writes:
> I'm migrating from Access til MySQL.

Over MS SQL Server, or are you in the wrong newsgroup?

> I got the count of total records in a variabel - (antalRecords)
> I got the count for the Field Q1 where the value value is = 'nej'
> Now I just need to calculate how many % of my records have the value 'nej'
> I access this worked very fine - but with MySQL ( and ASP) I just cant get
> it right!!! I go crazy ....

SELECT cast(100.0 * SUM (CASE Q1 WHEN 'nej' THEN 1 ELSE 0 END) / COUNT(*)
as decimal(5,2)
FROM tbl

This works on my SQL Server. I cannot promise that it works on YourSQL,
though. but at least it's ANSI.




--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация