sql语句按某些字段分组

时间:2015-08-05 02:25:17

标签: php mysql mysqli

你好我的所有数据库结构都像

 dsid - auto increment, did,coid,eid,dcid

现在我想选择did,coid,eid和dcid但是将它们分组为eid,就像我运行while循环时我应该得到eid1的所有值,然后是eid2然后eid3现在我得到dsid降序值为了

我正在使用此查询

 $somevari=mysqli_query($link,"select did,coid,eid,dcid from table where
 did='$variable'order by dsid desc"); //here i want to group them by eid
 while($thedatavariable=mysqli_fetch_array($somevari)){
 echo $thedatavariable['eid'];
 echo $thedatavariable['dcid'];
 }

 // i want all the values of dcid for a perticular eid and then other eid then other eid

1 个答案:

答案 0 :(得分:1)

您是否只想按特定顺序查看结果?如果是这样的话:

order by (eid = $eid) desc, eid

其中$eid是您的特定开斋节。

编辑:

在这种情况下,您似乎只是想要:

order by eid
相关问题