I tried to produce the same ordering and having some trouble
but here are two different queries you can start with:
SELECT
booki_id,bet_id,bettype,
group_concat(odds order by bet) betodds,line
FROM
bettable
GROUP BY
booki_id,bet_id,bettype,line
;
SELECT * FROM
(
SELECT
booki_id,bet_id,bettype,
group_concat(odds order by bet) betodds,line
FROM
bettable
GROUP BY
booki_id,bet_id,bettype,line
) AA
ORDER BY betodds
;
I also created sample data to test it with, and here it is:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.12 MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
MySQL (Current test) :: use test
Database changed
MySQL (Current test) :: DROP TABLE IF EXISTS bettable;
Query OK, 0 rows affected (0.03 sec)
MySQL (Current test) :: CREATE TABLE bettable
-> (
-> id INT NOT NULL AUTO_INCREMENT,
-> booki_id INT,
-> bet_id INT,
-> bet INT,
-> bettype VARCHAR(10),
-> line FLOAT,
-> odds FLOAT,
-> PRIMARY KEY (id)
-> );
Query OK, 0 rows affected (0.05 sec)
MySQL (Current test) :: INSERT INTO bettable (booki_id,bet_id,bet,bettype,line,odds) VALUES
-> (123,321,1,'3way',0.0,2.3),
-> (123,321,2,'3way',0.0,3.4),
-> (123,322,1,'3way',0.0,1.1),
-> (123,322,2,'3way',0.0,7.4),
-> (123,323,1,'3way',0.0,1.3),
-> (123,323,2,'3way',0.0,9.4);
Query OK, 6 rows affected (0.02 sec)
Records: 6 Duplicates: 0 Warnings: 0
MySQL (Current test) :: SELECT
-> booki_id,bet_id,bettype,
-> group_concat(odds order by bet) betodds,line
-> FROM
-> bettable
-> GROUP BY
-> booki_id,bet_id,bettype,line
-> ;
+----------+--------+---------+---------+------+
| booki_id | bet_id | bettype | betodds | line |
+----------+--------+---------+---------+------+
| 123 | 321 | 3way | 2.3,3.4 | 0 |
| 123 | 322 | 3way | 1.1,7.4 | 0 |
| 123 | 323 | 3way | 1.3,9.4 | 0 |
+----------+--------+---------+---------+------+
3 rows in set (0.01 sec)
MySQL (Current test) :: SELECT * FROM
-> (
-> SELECT
-> booki_id,bet_id,bettype,
-> group_concat(odds order by bet) betodds,line
-> FROM
-> bettable
-> GROUP BY
-> booki_id,bet_id,bettype,line
-> ) AA
-> ORDER BY betodds
-> ;
+----------+--------+---------+---------+------+
| booki_id | bet_id | bettype | betodds | line |
+----------+--------+---------+---------+------+
| 123 | 322 | 3way | 1.1,7.4 | 0 |
| 123 | 323 | 3way | 1.3,9.4 | 0 |
| 123 | 321 | 3way | 2.3,3.4 | 0 |
+----------+--------+---------+---------+------+
3 rows in set (0.02 sec)
MySQL (Current test) ::
You will have to play with the order of the whole rows from here.
Give it a Try !!!
I find that error particularly disturbing because MySQL introduced INFORMATION_SCHEMA with the introduction of MySQL 5.0. @gbn's answer shows that this bug
- goes back to MySQL 5.0.16
- was reported on ANY operating having this
- was based on the error happening in the IBM AIX 5.3 ML2 Operating System
- was closed 2006-01-26
MySQL's definition of a database is simply a subfolder under datadir.
Now, here is why I find the error particularly disturbing: The INFORMATION_SCHEMA database is not supposed to be a manifested folder under datadir.
For example
- datadir is /var/lib/mysql
- You have two databases: db1 and db2
Go to the OS and run the following:
cd /var/lib/mysql
ls -l
You will see several folders:
- mysql
- db1
- db2
- test (since MySQL default installs a test database)
- . (current dir)
- .. (parent dir)
In mysql, when you do SHOW DATABASES;
, you should not see .
and ..
. The source code would have made sure of that. Now, where is INFORMATION_SCHEMA? Guess what? All tables in the INFORMATION_SCHEMA are temp tables and use the memory storage engine. Also note that you do not a see a folder called INFORMATION_SCHEMA. Now, check out the definition of INFORMATON_SCHEMA.TABLES:
mysql> use information_schema
Database changed
mysql> show create table tables\G
*************************** 1. row ***************************
Table: TABLES
Create Table: CREATE TEMPORARY TABLE `TABLES` (
`TABLE_CATALOG` varchar(512) NOT NULL DEFAULT '',
`TABLE_SCHEMA` varchar(64) NOT NULL DEFAULT '',
`TABLE_NAME` varchar(64) NOT NULL DEFAULT '',
`TABLE_TYPE` varchar(64) NOT NULL DEFAULT '',
`ENGINE` varchar(64) DEFAULT NULL,
`VERSION` bigint(21) unsigned DEFAULT NULL,
`ROW_FORMAT` varchar(10) DEFAULT NULL,
`TABLE_ROWS` bigint(21) unsigned DEFAULT NULL,
`AVG_ROW_LENGTH` bigint(21) unsigned DEFAULT NULL,
`DATA_LENGTH` bigint(21) unsigned DEFAULT NULL,
`MAX_DATA_LENGTH` bigint(21) unsigned DEFAULT NULL,
`INDEX_LENGTH` bigint(21) unsigned DEFAULT NULL,
`DATA_FREE` bigint(21) unsigned DEFAULT NULL,
`AUTO_INCREMENT` bigint(21) unsigned DEFAULT NULL,
`CREATE_TIME` datetime DEFAULT NULL,
`UPDATE_TIME` datetime DEFAULT NULL,
`CHECK_TIME` datetime DEFAULT NULL,
`TABLE_COLLATION` varchar(32) DEFAULT NULL,
`CHECKSUM` bigint(21) unsigned DEFAULT NULL,
`CREATE_OPTIONS` varchar(255) DEFAULT NULL,
`TABLE_COMMENT` varchar(2048) NOT NULL DEFAULT ''
) ENGINE=MEMORY DEFAULT CHARSET=utf8
1 row in set (0.05 sec)
I lay full blame for this error on the source code because just as mysql bypasses .
and ..
as special case folders that are not to be considered databases, INFORMATION_SCHEMA is supposed to be considered a s special case folder as well, a special case folder that does not have a manifested file under the datadir.
I would highly recommend just upgrading MySQL to the latest version because, as @gbn found, there was a bug report but it is marked as closed. This could only happen
- if you are still running a very old version of mysql
- this situation was not properly handled in the source code for the Ubuntu OS
@gbn gets a +1 from me for finding the bug report which helped me look a little deeper
Best Answer
So it seems like you're missing the where clause which would filter out the undesirable results. In this example I'm assuming 2 is a decent threshold and using a between clause to limit the output. Greater than with a limit would also work but it really depends on the dataset.
Here's the example using greater than.