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|
+------------+---+-+---+
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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.