Php 要按某个字段分组的sql语句

Php 要按某个字段分组的sql语句,php,mysql,mysqli,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='$va

大家好,我的数据库结构是这样的

 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

您是否只希望结果按特定顺序排列?如果是:

order by (eid = $eid) desc, eid
其中,
$eid
是您的特定eid

编辑:

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

order by eid

不,我不想要所有结果,但按eid排序(不是所有eid的一个eid)