468,119 Members | 1,981 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,119 developers. It's quick & easy.

show numbers of records as % ???

Hi
I'm migrating from Access til MySQL.
Works fine so far - but one thing is nearly killing me:

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 ....

My code looks like this :

strSQL="SELECT COUNT(Q1) AS Q1_nej FROM Tbl_evaluering " &_
"WHERE Q1 = 'NEJ' "
set RS = connection.Execute(strSQL)
antal_nej = RS("Q1_nej")
procent_nej = formatNumber((antal_nej),2)/antalrecords * 100

Hope ...praying for help ...Please ;-)
best wishes -Otto - Copenhagen
Feb 15 '07 #1
2 2424
On Feb 15, 9:21 pm, "Otto" <ottoleh...@tele.dkwrote:
Hi
I'm migrating from Access til MySQL.
Works fine so far - but one thing is nearly killing me:

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 ....

My code looks like this :

strSQL="SELECT COUNT(Q1) AS Q1_nej FROM Tbl_evaluering " &_
"WHERE Q1 = 'NEJ' "
set RS = connection.Execute(strSQL)
antal_nej = RS("Q1_nej")
procent_nej = formatNumber((antal_nej),2)/antalrecords * 100

Hope ...praying for help ...Please ;-)
best wishes -Otto - Copenhagen
SELECT (COUNT( t1.mytable_id ) / COUNT( t2.mytable_id )) *100 percent
FROM `mytable` t1
RIGHT JOIN mytable t2 ON t1.mytable_id = t2.mytable_id
AND t2.myfield = 'nej';

Feb 16 '07 #2
Otto wrote:
>Hi
I'm migrating from Access til MySQL.
Works fine so far - but one thing is nearly killing me:

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 ....

My code looks like this :

strSQL="SELECT COUNT(Q1) AS Q1_nej FROM Tbl_evaluering " &_
"WHERE Q1 = 'NEJ' "
set RS = connection.Execute(strSQL)
antal_nej = RS("Q1_nej")
procent_nej = formatNumber((antal_nej),2)/antalrecords * 100

Hope ...praying for help ...Please ;-)
best wishes -Otto - Copenhagen

One reason code might not work..
Try using Concat(string,string) .... & is not valid MYSQL syntax for
adding strings

Feb 17 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by chris vettese | last post: by
6 posts views Thread by GSpiggle | last post: by
10 posts views Thread by RobK | last post: by
13 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.