1
Well, I have a "voting uniform" table that receives in the columns "voto_uniforme1", "voto_uniforme2" and "voto_uniforme3" a value of type "BOOLEAN", where 1 means that the person voted in this uniform and 0 the other way, follows the logical table image:
With this command:
SELECT(SELECT COUNT(voto_uniforme1) FROM votos_uniforme WHERE votos_uniforme.voto_uniforme1 = 1) AS Uniforme1,(SELECT COUNT(voto_uniforme2) FROM votos_uniforme WHERE votos_uniforme.voto_uniforme2 = 1) AS Uniforme2, (SELECT COUNT(voto_uniforme3) FROM votos_uniforme WHERE votos_uniforme.voto_uniforme3 = 1) AS Uniforme3
He returns it to me:
But I need him to show me how a ranking, for example who has the most votes comes first, who has the most amount between the other two comes second, and the smallest comes last third, what would be the best way to do that ?
In this case this "DESC" orders from the largest to the smallest ?
– Lone Tonberry
@Lonetonberry this from the largest to the smallest, if you want in normal order remove the
DESC
or putASC
– novic
An error appeared to me, is that I need to make a VIEW with this code and when I try to save as a VIEW shows this error: "#1349 - View’s SELECT contains a subquery in the FROM clause"
– Lone Tonberry
@Lonetonberry good ai you put another point, for creation of the view I did the explaining Edit, note in the answer how it should be created and how it should be used with ordering, is an example.
– novic
So in this case, sorting cannot be part of the view in any way ?
– Lone Tonberry
@Not Lonetonberry, because that would deprive you of using the
View
for other purposes such as filters, ordering and so on (this is normal in benches). If you want to use a Procedure (Procedure) you could!– novic