3

Here is my current query:

select No,
       (select count(no) from textvote group by no) /
       (select count(no) from textvote where no like '%Ginoo%')
from textvote

Table: textvote

No      Sender
Ginoo 1 9307895654
Ginoo 1 9566551234
Ginoo 1 9232235643
Ginoo 2 9225557878

This must be the result:

No      Total
Ginoo 1 75%
Ginoo 2 25%
Lughen
  • 45
  • 5

1 Answers1

2

Is this what you had in mind:

SELECT no,
       CONCAT(CAST(100*count(*) /
                   (select count(*) from textvote where no like '%Ginoo%') AS CHAR(50)), '%') AS Total
FROM textvote
WHERE no LIKE '%Ginoo%'
GROUP BY no

This query is working correctly in the demo below:

SQLFiddle

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • I want to achieve the result by this Ginoo 1 has 3 votes divided by a total of votes of 4 and Ginoo 2 has 1 vote divided by a total of 4 votes – Lughen Jan 26 '17 at 05:37
  • select no, count(no) / (select count(no) from textvote where no like '%Ginoo%') * 100 from textvote group by no" give the wrong output – Lughen Jan 26 '17 at 05:58
  • 1
    Update your question with the _exact_ output you expect and you should get an answer. – Tim Biegeleisen Jan 26 '17 at 06:00
  • Ginoo 1 gets the result of 33% instead of 75% – Lughen Jan 26 '17 at 08:28
  • Still the results is Ginoo 1 has 33.33% and Ginoo 2 has 66.66% – Lughen Jan 26 '17 at 08:36
  • My query is working correctly using the data you provided. If you still have a problem, then something is wrong with your data. – Tim Biegeleisen Jan 26 '17 at 08:45
  • 1
    Yes I've check it my self. Ginoo 1 has only 1 vote and Ginoo 2 has 2. total of the is 3 only. My mistake. Thank you Tim – Lughen Jan 26 '17 at 08:49