Jump to content

SQL help for extracting common details


webdev1

Recommended Posts

I normalized the data into table randomn.

 

id int,

seq int

ball int

 

then

    SELECT CONCAT_WS(',', A,B,C) as balls, COUNT(*) as occ
    FROM
    (
    SELECT a.id, a.ball as A, b.ball as B, c.ball as C
    FROM randomn a
    JOIN randomn b ON a.id = b.id AND a.seq < b.seq
    JOIN randomn c ON c.id = b.id AND b.seq < c.seq
    ) as X
    GROUP BY balls
    ORDER BY occ DESC

Barand normalized the data before applying this query, as I suggested earlier.

Basically he transformed the data from 

 

id ball1, ball2, ball3 etc

1, 5,7,9,...

 

to:

 

id, ballvalue, ballposition

1,5,1

1,7,2

1,9,2

 

which you can do using something like 

 

CREATE TABLE random_normalized AS 

SELECT * FROM

(

SELECT id, ball1 AS ball, 1 AS seq FROM random

UNION ALL

SELECT id, ball2 AS ball, 2 AS seq FROM random

UNION ALL

...

) AS n;

 

That table can then be used by Barand's query.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.