但是这个问题和前一个问题之间的差异,我想让许多俱乐部的名字中的一个集体选手或一组球员,例如:
El Ahly俱乐部的名字有12个玩家,我想把它分成3个队,每个队有4个球员,我想计算每个俱乐部名字里面有多少球队
然后把它们放在不变的数字(组)中4 8 16 32 64 128 256基于团队打印**任何一个WORD **之间他们之间的东西,过滤数据后,选择full_name,club_name从玩家其中y_of_birth = 2000所需的输出应该是这样的:
更新 :
+----+------+---------------------+ | full_name | club_name | +--------------+------------------+ | Ahmed Sayed | El Ahly | +--------------+------------------+ | Kareem Gaber | El Ahly | +--------------+------------------+ | Maher Zein | El Ahly | +--------------+------------------+ | Mohab SAEed | El Ahly | +----+------+--+------------------+ | ahmed shawky | Petroget | +--------------+------------------+ | shaker ali | Petroget | +--------------+------------------+ | omar SAEd | Petroget | +--------------+------------------+ | moataz Gamal | Petroget | +------+-------+------------------+ | **ANY WORD** | | +--------------+------------------+ | **ANY WORD** | | +--------------+------------------+ | **ANY WORD** | | +--------------+------------------+ | **ANY WORD** | | +--------------+------------------+ | husein mazen | Cocorico | +--------------+------------------+ | hassan maged | Cocorico | +--------------+------------------+ | maged ahmoud | Cocorico | +--------------+------------------+ | zakareya gad | Cocorico | +--------------+------------------+ | Kamal saber | El Ahly | +--------------+------------------+ | gamel kamel | El Ahly | +--------------+------------------+ | omar galal | El Ahly | +--------------+------------------+ | Kamal saber | El Ahly | +--------------+------------------+ | **ANY WORD** | | +--------------+------------------+ | **ANY WORD** | | +--------------+------------------+ | **ANY WORD** | | +--------------+------------------+ | **ANY WORD** | | +--------------+------------------+ | khaled zein | Petroget | +--------------+------------------+ | shady sameer | Petroget | +--------------+------------------+ | wahed mahmoud| Petroget | +--------------+------------------+ | samy shahen | Petroget | +----+------+--+------------------+ | Mohamed gad | El Ahly | +----+------+--+------------------+ | ehab zeyad | El Ahly | +----+---------+------------------+ | moaz maged | El Ahly | +--------------+------------------+ | mazen mahmod | El Ahly | +--------------+------------------+
在这个例子中,有两组** ANY WORD **,因为它是一个6组,并将它们放在8个不变的组中,发现在4或8或16或32或64或128或256个数字之间,而没有相邻2 **任何一个字**或两个相邻的club_name
例子 :
4名玩家作为一名球员
如果结果选择full_name,club_name从玩家,其中y_of_birth = 2000是12个玩家,这意味着12个玩家= 3组,因为每个组有4个玩家下一步打印**任何一个字** 4次(注意:**任何一个字**是这些组之一)在3组之间,所以输出将是这样的:
+----+------+---------------------+ | full_name | club_name | +--------------+------------------+ | Ahmed Sayed | El Ahly | +--------------+------------------+ | Kareem Gaber | El Ahly | +--------------+------------------+ | Maher Zein | El Ahly | +--------------+------------------+ | Mohab SAEed | El Ahly | +----+------+--+------------------+ | ahmed shawky | Petroget | +--------------+------------------+ | shaker ali | Petroget | +--------------+------------------+ | omar SAEd | Petroget | +--------------+------------------+ | moataz Gamal | Petroget | +------+-------+------------------+ | **ANY WORD** | | +--------------+------------------+ | **ANY WORD** | | +--------------+------------------+ | **ANY WORD** | | +--------------+------------------+ | **ANY WORD** | | +--------------+------------------+ | Kamal saber | El Ahly | +--------------+------------------+ | gamel kamel | El Ahly | +--------------+------------------+ | omar galal | El Ahly | +--------------+------------------+ | Kamal saber | El Ahly | +--------------+------------------+
结论:
4 8 16 32 64 128 256是不可变组
组4应该用16个玩家填写**任意一个字,**之间没有相邻的东西:
+----+------+---------------------+ | full_name | club_name | +--------------+------------------+ | Ahmed Sayed | El Ahly | +--------------+------------------+ | Kareem Gaber | El Ahly | +--------------+------------------+ | Maher Zein | El Ahly | +--------------+------------------+ | Mohab SAEed | El Ahly | +----+------+--+------------------+ | ahmed shawky | Petroget | +--------------+------------------+ | shaker ali | Petroget | +--------------+------------------+ | omar SAEd | Petroget | +--------------+------------------+ | moataz Gamal | Petroget | +------+-------+------------------+ | **ANY WORD** | | +--------------+------------------+ | **ANY WORD** | | +--------------+------------------+ | **ANY WORD** | | +--------------+------------------+ | **ANY WORD** | | +--------------+------------------+ | Kamal saber | El Ahly | +--------------+------------------+ | gamel kamel | El Ahly | +--------------+------------------+ | omar galal | El Ahly | +--------------+------------------+ | Kamal saber | El Ahly | +--------------+------------------+
第8组应该填充32名玩家,** **任意一个字,**之间没有相邻的东西:
+----+------+---------------------+ | full_name | club_name | +--------------+------------------+ | Ahmed Sayed | El Ahly | +--------------+------------------+ | Kareem Gaber | El Ahly | +--------------+------------------+ | Maher Zein | El Ahly | +--------------+------------------+ | Mohab SAEed | El Ahly | +----+------+--+------------------+ | ahmed shawky | Petroget | +--------------+------------------+ | shaker ali | Petroget | +--------------+------------------+ | omar SAEd | Petroget | +--------------+------------------+ | moataz Gamal | Petroget | +------+-------+------------------+ | **ANY WORD** | | +--------------+------------------+ | **ANY WORD** | | +--------------+------------------+ | **ANY WORD** | | +--------------+------------------+ | **ANY WORD** | | +--------------+------------------+ | husein mazen | Cocorico | +--------------+------------------+ | hassan maged | Cocorico | +--------------+------------------+ | maged ahmoud | Cocorico | +--------------+------------------+ | zakareya gad | Cocorico | +--------------+------------------+ | Kamal saber | El Ahly | +--------------+------------------+ | gamel kamel | El Ahly | +--------------+------------------+ | omar galal | El Ahly | +--------------+------------------+ | Kamal saber | El Ahly | +--------------+------------------+ | **ANY WORD** | | +--------------+------------------+ | **ANY WORD** | | +--------------+------------------+ | **ANY WORD** | | +--------------+------------------+ | **ANY WORD** | | +--------------+------------------+ | khaled zein | Petroget | +--------------+------------------+ | shady sameer | Petroget | +--------------+------------------+ | wahed mahmoud| Petroget | +--------------+------------------+ | samy shahen | Petroget | +----+------+--+------------------+ | Mohamed gad | El Ahly | +----+------+--+------------------+ | ehab zeyad | El Ahly | +----+---------+------------------+ | moaz maged | El Ahly | +--------------+------------------+ | mazen mahmod | El Ahly | +--------------+------------------+
等等
第16组
第32组
第64组
第128组
组256
编辑:
我从Gordon Linoff得到这个查询
select p.* from (select p.*,(@rn := if(@c = club_name,@rn + 1,if(@c := club_name,1,1) ) ) as seqnum from players p cross join (select @c := '',@rn := 0) params order by club_name ) p order by floor((seqnum - 1) / 4),club_name
结合数据过滤后:
select p.* from (select p.full_name,club_name,1) ) ) as seqnum from players p cross join (select @c := '',@rn := 0) params WHERE `y_of_birth` LIKE N'%2000%' order by club_name ) p order by floor((seqnum - 1) / 4),club_name
+----+------+---------------------+ | full_name | club_name | +--------------+------------------+ | Ahmed Sayed | El Ahly | +--------------+------------------+ | Kareem Gaber | El Ahly | +--------------+------------------+ | Maher Zein | El Ahly | +--------------+------------------+ | Mohab SAEed | El Ahly | +----+------+--+------------------+ | kamal mado | Cocorico | +--------------+------------------+ | hossam magdy | Cocorico | +--------------+------------------+ | sayed ammar | Cocorico | +--------------+------------------+ | karem gad | Cocorico | +--------------+------------------+ | Mohamed gad | El Ahly | +----+------+--+------------------+ | ehab zeyad | El Ahly | +----+---------+------------------+ | moaz maged | El Ahly | +--------------+------------------+ | mazen mahmod | El Ahly | +--------------+------------------+ | shaker ali | Petroget | +--------------+------------------+ | omar SAEd | Petroget | +--------------+------------------+ | moataz Gamal | Petroget | +--------------+------------------+ | gamael zayed | Petroget | +--------------+------------------+ | husein mazen | Cocorico | +--------------+------------------+ | mazen kamal | Cocorico | +--------------+------------------+ | maged ahmoud | Cocorico | +--------------+------------------+ | mesho kareem | Cocorico | +--------------+------------------+ | mano mazen | Petroget | +--------------+------------------+ | shady srour | Petroget | +--------------+------------------+ | mamdouh gamal| Petroget | +--------------+------------------+ | khaled zein | Petroget | +--------------+------------------+ | husein mazen | Cocorico | +--------------+------------------+ | hassan maged | Cocorico | +--------------+------------------+ | maged ahmoud | Cocorico | +--------------+------------------+ | zakareya gad | Cocorico | +--------------+------------------+ | shady sameer | Petroget | +--------------+------------------+ | wahed mahmoud| Petroget | +--------------+------------------+ | samy shahen | Petroget | +----+------+--+------------------+ | abdo samy | Petroget | +----+------+--+------------------+
任何帮助将不胜感激!
那么有一个常数,你总是比较哪个是团队的大小.
我会做一个子查询,将团队的数量统计为玩家,并按以下方式使用它:
select t.*,x.total_players --,row_number() over(order by t.team_name) row_id from team_table t join ( select team_id,count(1) total_playeRSS from team_table group by team_id ) x on x.team_id = t.team_id order by t.team_name
<?PHP function add_some_word($playerCount) { if ($playerCount >4 && $playerCount <= 8) { echo '*** SOME WORD***'; echo '*** SOME WORD***'; echo '*** SOME WORD***'; } else if ($playerCount >4 && $playerCount <= 8) { echo '*** SOME WORD***'; echo '*** SOME WORD***'; } // etc. } ?>
使用结果集中的row_id,您可以看到一个团队何时开始和结束.
所以当它吐出行时,它可能是这样的:
<?PHP $currentTeamName = ""; while ($row = pg_fetch_array($result,null,PGsql_ASSOC)) { // echo data you would normally send out if ($currentTeamName != $row['team_name']) { add_some_word($row['total_players']); } } ?>
我希望得到你的问题.我快速冲破这个,但我认为这将有所帮助!