gpt4 book ai didi

php - 如何使用 PHP 和 MySQL 对表值进行排序?

转载 作者:太空宇宙 更新时间:2023-11-03 10:42:04 25 4
gpt4 key购买 nike

我需要使用 MySQL 和 PHP 使用一个订单获取 MySQL 表值。我在下面提供了我的表格。

数据库猫:

id     cat_name   cat_id     order_no

1 aaa 10 1

2 ggg 10 30

3 fff 10 11


4 sss 10 12

5 ddd 10 5

在这里,我尝试使用查询根据 order_no 列值获取数据:

select * from db_cat where cat_id='10' order by order_no asc

但是它给了我错误的订单数据,比如 (11,12,30,1,5) 我应该得到这样的数据订单 (1,5,11,12,30 ).

我的 order_no 数据类型是 varchar

最佳答案

您可以按顺序使用强制转换

select * from db_cat where cat_id='10' order by cast(order_no as int) asc

关于php - 如何使用 PHP 和 MySQL 对表值进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36809719/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com