desc php,php mysql asc / desc命令

表:

**timeslot**:

----------

id_timeslot times

1 09:00

2 09:30

3 10:00

4 10:30

5 11:00

**bookslot**

id id_timeslot date b_ref

-------------------------------------------

1 2 2010-02-22 001

2 3 2010-02-22 001

3 4 2010-02-22 001

4 5 2010-02-22 001

5 2 2010-02-25 002

6 3 2010-02-27 003

7 4 2010-02-27 003

8 5 2010-02-27 003

的PHP

$q = $mysqli->query("SELECT * FROM bookslot

LEFT JOIN timeslot ON bookslot.id_timeslot = timeslot.id_timeslot

WHERE bookslot.status = 1

GROUP BY bookslot.b_ref

ORDER BY bookslot.date ASC, bookslot.id_timeslot ASC LIMIT 20");

HTML结果:

DATE TIMES

2010-02-22 10:30

2010-02-25 09:30

2010-02-27 11:00

任何人都注意到桌上的结果.次是不正确的顺序?

我改变了另一种方式与ASC / DESC,仍然显示最后一个id_timeslot的时间吗?

预期结果:

DATE TIMES

2010-02-22 09:30

2010-02-25 09:30

2010-02-27 10:00

解决方法:

您的GROUP BY bookslot.b_ref正在对记录进行分组,因此在每种情况下您只会看到最后一次.

尝试使用

SELECT date, time, MIN(bookslot.id_timeslot)

FROM bookslot

LEFT JOIN timeslot ON bookslot.id_timeslot = timeslot.id_timeslot

WHERE bookslot.status = 1

GROUP BY bookslot.b_ref

ORDER BY bookslot.date ASC, bookslot.id_timeslot ASC LIMIT 20

标签:group-by,date,mysql,sql,php

来源: https://codeday.me/bug/20191023/1913387.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值