简体   繁体   English

sql语句按某个字段分组

[英]sql statement to group by some field

hello all my database structure is like 你好我所有的数据库结构就像

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

now i want to select did,coid,eid and dcid but group them by eid like when i run the while loop i should get all the values for eid1 and then for eid2 and then eid3 right now i get values in dsid descending order 现在我想选择did,coid,eid和dcid,但是按eid对其进行分组,例如当我运行while循环时,我应该先获取eid1的所有值,然后获取eid2的所有值,然后再获取eid3的所有值,现在我以dsid降序排列

i am using this query 我正在使用此查询

 $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

Do you just want the results in a particular order? 您是否只想要特定顺序的结果? If so: 如果是这样的话:

order by (eid = $eid) desc, eid

where $eid is your particular eid. $eid是您的特定eid。

EDIT: 编辑:

In that case, you would seem to just want: 在这种情况下,您似乎只想:

order by eid

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM