doukanhua0752 2019-02-17 12:14
浏览 85
已采纳

SQL GROUP按日行,然后在DESC中进行分组(仍需要帮助)

Right now i'm just ordering all the rows by DESC, but i want to put the rows that are created the same day into groups and the groups in DESC.

This is what i currenly have:

$sql3 = "SELECT * FROM test3 WHERE aktiv LIKE 'Ja' ORDER BY date DESC ";
$result = mysqli_query($conn, $sql3);

This is my table: enter image description here

So it will echo out all the rows that where created on 17 first then 16 and 14 into groups, then i can echo out the date of the different groups. So do i need to use GROUP BY or first find the dates then put it into groups.

I have tried different ways of doing it, but its so many different answers around and can't find the right solution for me, so i need a bit of help.

  • 写回答

1条回答 默认 最新

  • doucitao2944 2019-02-17 12:19
    关注

    use aggregation function min for id and date for datetime to date

     SELECT date(date) as day,aktiv,betvalue,min(id)
     FROM test3 WHERE aktiv LIKE 'Ja'  group by day,aktiv,betvalue
     ORDER BY date(date) DESC 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器