簡體   English   中英

sql語句按某個字段分組

[英]sql statement to group by some field

你好我所有的數據庫結構就像

 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM