Jump to content

need help getting right query


karimali831

Recommended Posts

if you were clear about your requirements while starting a thread .....it would have saved lot of time for us.

After so many replies , you are telling us that  the query you had in the first step is what you required  and now come up with a new requirement . Its waste of time

 

Read the forums rules once again.

 

Unless you are clear about your requirements and provide us sample output with dummy data , don't expect any reply.

Link to comment
Share on other sites

if you were clear about your requirements while starting a thread .....it would have saved lot of time for us.

After so many replies , you are telling us that  the query you had in the first step is what you required  and now come up with a new requirement . Its waste of time

 

Read the forums rules once again.

 

Unless you are clear about your requirements and provide us sample output with dummy data , don't expect any reply.

 

Sorry sir, English not my first and I think you miss-understood something.

 

there is two requests, one mikosiko gave the answer too but he did typo error

 

a.clan1,

b.clan1 AS 'versus',

 

when it was suppose to be

 

a.clan2,

b.clan1 AS 'versus',

 

my first requirement is working fine, my second was to insert values of the weeks and it is hard to explain

that is why I made image. :(

 

 

Link to comment
Share on other sites

Algorithm for assigning week is something you have to implement outside mysql.

 

And it depends on how many players are there in each group (MIN and MAX possible values) and number of players in each group are always equal or not ?

 

A player plays only one match in a week is strictly true or it changes based on number of matches.

 

you haven't provide any of these details .....and still expect understand or assume everything correctly.

 

 

Link to comment
Share on other sites

  • 2 weeks later...

I just noticed something I can't believe I didn't spot, it generates 7 matches for clan1 which are all the matches but for clan2 is only generates 4 matches if you take a look at image in previous post.

 

That is because clan2 player is not playing match with another clan2 player ... in that case you need to have another union

 

 

 

can you show me how to add this other union please?

Because the query it still duplicated same matches:-

 

http://s17.postimage.org/mvueq1rql/prob4.png

 

Code:

 

                   safe_query("INSERT INTO ".PREFIX."cup_matches ($type, $type_opp, matchno, clan1, clan2, comment, 1on1) 
                   (SELECT a.$type,
                          a.$type_opp,
                          a.matchno,
                          a.clan1,
                          b.clan2 AS 'versus',
                          a.comment,
                          a.1on1
                   FROM ".PREFIX."cup_matches a
                        JOIN ws_bi2_cup_matches b ON a.$type = b.$type AND b.$type = '$let_alpha' 
                                                           AND b.matchno = '$ID' 
                                                           AND a.clan2 != b.clan2				
                                                           AND b.type = 'gs'
                   WHERE a.matchno = '$ID'
                     AND a.type = 'gs')
                   UNION
                   (SELECT a.$type,
                          a.$type_opp,
                          a.matchno,
                          a.clan2,
                          b.clan1 AS 'versus',
                          a.comment,
                          a.1on1
                   FROM ".PREFIX."cup_matches a
                        JOIN ws_bi2_cup_matches b ON a.$type = b.$type AND b.$type = '$let_alpha' 
                                                           AND b.matchno = '$ID' 
                                                           AND a.clan1 != b.clan1 
                                                           AND b.type = 'gs'
                   WHERE a.matchno = '$ID'
                     AND a.type = 'gs')
                   ORDER BY clan1 DESC, versus");

Link to comment
Share on other sites

Please ignore previous post!!

 

It does not duplicate anything, clan1 rows are all generated (7 per team) but in clan2 only 4 matches each instead of 7:

Mentioned in Illusion post I  need ANOTHER UNION?

 

http://s14.postimage.org/60uhbpe0f/prob5.png

 

This is the code:-

 

                   safe_query("INSERT INTO ".PREFIX."cup_matches ($type, $type_opp, matchno, clan1, clan2, comment, 1on1) 
                   (SELECT a.$type,
                          a.$type_opp,
                          a.matchno,
                          a.clan1,
                          b.clan2 AS 'versus',
                          a.comment,
                          a.1on1
                   FROM ".PREFIX."cup_matches a
                        JOIN ws_bi2_cup_matches b ON a.$type = b.$type AND b.$type = '$let_alpha' 
                                                           AND b.matchno = '$ID' 
                                                           AND a.clan2 != b.clan2				
                                                           AND b.type = 'gs'
                   WHERE a.matchno = '$ID'
                     AND a.type = 'gs')
                   UNION
                   (SELECT a.$type,
                          a.$type_opp,
                          a.matchno,
                          a.clan1,
                          b.clan1 AS 'versus',
                          a.comment,
                          a.1on1
                   FROM ".PREFIX."cup_matches a
                        JOIN ws_bi2_cup_matches b ON a.$type = b.$type AND b.$type = '$let_alpha' 
                                                           AND b.matchno = '$ID' 
                                                           AND a.clan1 < b.clan1 
                                                           AND b.type = 'gs'
                   WHERE a.matchno = '$ID'
                     AND a.type = 'gs')
                   ORDER BY clan1 DESC, versus");

Link to comment
Share on other sites

Tried using my brain this time... it seems ok! :D

Need to make sure there is no problem, this is the long query:-

 

                   safe_query("INSERT INTO ".PREFIX."cup_matches ($type, $type_opp, matchno, clan1, clan2, comment, 1on1) 
                   (SELECT a.$type,
                          a.$type_opp,
                          a.matchno,
                          a.clan1,
                          b.clan2 AS 'versus',
                          a.comment,
                          a.1on1
                   FROM ".PREFIX."cup_matches a
                        JOIN ws_bi2_cup_matches b ON a.$type = b.$type AND b.$type = '$let_alpha' 
                                                           AND b.matchno = '$ID' 
                                                           AND a.clan2 != b.clan2				
                                                           AND b.type = 'gs'
                   WHERE a.matchno = '$ID'
                     AND a.type = 'gs')
                   UNION
                   (SELECT a.$type,
                          a.$type_opp,
                          a.matchno,
                          a.clan1,
                          b.clan1 AS 'versus',
                          a.comment,
                          a.1on1
                   FROM ".PREFIX."cup_matches a
                        JOIN ws_bi2_cup_matches b ON a.$type = b.$type AND b.$type = '$let_alpha' 
                                                           AND b.matchno = '$ID' 
                                                           AND a.clan1 < b.clan1 
                                                           AND b.type = 'gs'
                   WHERE a.matchno = '$ID'
                     AND a.type = 'gs')		     
                   UNION
                   (SELECT a.$type,
                          a.$type_opp,
                          a.matchno,
                          a.clan2,
                          b.clan2 AS 'versus',
                          a.comment,
                          a.1on1
                   FROM ".PREFIX."cup_matches a
                        JOIN ws_bi2_cup_matches b ON a.$type = b.$type AND b.$type = '$let_alpha' 
                                                           AND b.matchno = '$ID' 
                                                           AND a.clan2 < b.clan2 
                                                           AND b.type = 'gs'
                   WHERE a.matchno = '$ID'
                     AND a.type = 'gs')	   
                   ORDER BY clan1 DESC, versus");

 

Fine?

Link to comment
Share on other sites

Algorithm for assigning week is something you have to implement outside mysql.

 

And it depends on how many players are there in each group (MIN and MAX possible values) and number of players in each group are always equal or not ?

 

A player plays only one match in a week is strictly true or it changes based on number of matches.

 

you haven't provide any of these details .....and still expect understand or assume everything correctly.

 

 

 

Finally the query is ok now :)

The second part of it is to split in weekly divisions..

 

Ok,

 

-> each group will have even amount of teams

-> 7 matches per team is for 7 weeks, each match per week

-> league is not limited to max signups

 

if league is for 16 teams there will only be 2 groups, a and b:

 

min: 4 per group

max: 8 per group

 

-> group a which holds up to 8 teams

-> group b which holds up to 8 teams

-> all vs. all therefore is 16/2 * 7 weeks = 56 max matches (28 matches for group a and 28 for group b)

 

if league is for 32 teams there will only be 4 groups, a, b, c and d:

 

min: 4 per group

max: 8 per group

 

-> each group holds up to 8 teams each

-> all vs. all therefore is 32/2 * 7 weeks = 112 matches (112 / 4 groups  = 28 matches in each group)

 

if league is for 64 teams there will be 8 groups (a-h):

 

min: 4 per group

max: 8 per group

 

-> each group holds up to 8 teams each

-> all vs. all therefore is 64/2 * 7 =  224 matches (224 / 8 groups = 28 matches in each group)

 

if league is for 128 teams there will be 8 groups (a-h);

 

min: 8 per group

max: 16 per group

 

-> each group holds up to 16 teams each

-> all vs. all therefore is 128/2 * 7 = 448 matches (448 / 8 groups = 56 matches in each group)

Link to comment
Share on other sites

You are totally lost. Its basic elementary mathematical problem.

 

(i) If you have more than two groups then assuming that you have proper mechanism to group the players then your query needs to be executed n-1 ( n be the number of groups ) times with current logic .

Assuming a,b,c,d as groups  : a-b, a-c, a-d, b-c, b-d, c-d

 

(ii) Assuming that you have a1,a2,a3 in  group a and b1,b2,b3 in group

 

your current query fetches following combinations only

a1-b2

a1-b3

a2-b1

a2-b3

a3-b1

a3-b2

a1-a2

a1-a3

a2-a3

b1-b2

b1-b3

b2-b3

 

as you can see following combinations are ignored

a1-b1

a2-b2

a3-b3

 

if you have n number of teams in each group then it will fetch n(n-1)  + 2 (n-1) records only because o the condition a.clan2 != b.clan2. If you remove that condition you will get missed 3 combinations also assuming that those 3 are also valid for your requirement ... then in total you get  n*n  + 2 (n-1)

 

so if you have 8 players in each group then total possible matches are  8*8 + 2 (8-1) = 78

Note that your current query fetches only  8*7 + 2(8-1)=70

 

As per your calculation given below  its only 56 - which is  wrong as per my understanding.

 

if n^2 + 2(n-1) are total number of matches then each player plays  2n-1 matches  .. which implies that all the matches will be played in 2n-1 weeks.

Now you can order the results by clan1 and use simple math to assign week.

 

 

 

 

 

 

Link to comment
Share on other sites

I'm no wizz at logics and mathematics but you are making it seem more complicated than it seems, the query fetches ALL combinations, there is two unions in the query now and if max is reached it will always have 28 matches per group.

 

if 4 matches in each group (which will be for 8 players) 4 times 7 = 28

 

Where in this pic do you see a missed combination? Each player has 7 matches each.

http://s13.postimage.org/i2apegtz9/solved.png

 

solved.png

 

The complicated theory now is assigning weeks..

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.