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 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?