0

I really tried to do this by myself but seems that there is too complex query for a newbie like me.

on dgpl_se_bets1x2 table i have values for:

id, id_mat, prev, note, datetime

what is important of these:

id_mat = match id

prev = bet placed by user, values are 1, x or 2.

I want to print statistics about made bets, here is few lines for example:

+--+------+----+----+-------------------+
|id|id_mat|prev|note|datetime           |
+--+------+----+----+-------------------+
|6 |442   |2   |1   |2014-01-03 11:04:08|
+--+------+----+----+-------------------+
|5 |442   |1   |1   |2014-01-03 11:04:08|
+--+------+----+----+-------------------+
|5 |449   |1   |1   |2014-01-02 16:40:28|
+--+------+----+----+-------------------+
|6 |449   |1   |0   |2014-01-02 16:40:28|
+--+------+----+----+-------------------+
|7 |442   |2   |0   |2014-01-03 11:04:08|
+--+------+----+----+-------------------+
|8 |442   |2   |1   |2014-01-03 11:04:08|
+--+------+----+----+-------------------+
|7 |636   |2   |0   |2014-01-03 15:46:34|
+--+------+----+----+-------------------+

So there are matches 5,6,7 and 8. And from that data I want to print out something like this:

+------------+-+-+-+
|Match Number|1|x|2|
+------------+-+-+-+
|5           |2|0|0|
+------------+-+-+-+
|6           |1|0|1|
+------------+-+-+-+
|7           |0|0|2|
+------------+-+-+-+
|8           |0|0|1|
+------------+-+-+-+

Or even better, with percentages:

+------------+---+-+---+
|Match Number|1  |x|2  |
+------------+---+-+---+
|5           |100|0|0  |
+------------+---+-+---+
|6           |50 |0|50 |
+------------+---+-+---+
|7           |0  |0|100|
+------------+---+-+---+
|8           |0  |0|100|
+------------+---+-+---+

1 Answer 1

2

Give this a try

SELECT id_mat,
    (SUM(prev='1')/COUNT(*))*100 AS prev1,
    (SUM(prev='x')/COUNT(*))*100 AS prevX,
    (SUM(prev='2')/COUNT(*))*100 AS prev2
FROM dgpl_se_bets1x2
GROUP BY id_mat;
Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what I was looking for. Wasnt so hard that I thought it would be. Thank you very much Patrick :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.