mysql忽略空的行降序排序 本帖最后由 lujunjie1993 于 2011-12-25 15:59:26 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 数据库是下面,字段是id和time,按time降序排序,也要忽略空的那一行。id time1 12 23 35 56 67 78 89 9最终显示如下id time9 98 87 76 65 53 32 21 1就是忽略了空的那一行。 select * from 表 order by 字段 的结果中不可以出现空记录在数字记录的中间。 建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。 参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html 1. 你的 create table xxx .. 语句 2. 你的 insert into xxx ... 语句 3. 结果是什么样,(并给以简单的算法描述) 4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL) 这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。 select *from tbwhere id is not nullorder by id desc 我在帖子的1楼已经说得很明白了。MYsql数据库是id time1 12 23 35 56 67 78 89 9我试了“select * from 表 order by 字段”的确能按字段time降序排序,结果显示id time9 98 87 76 65 53 32 21 1我要显示9 98 87 76 65 53 32 21 1求代码 如果是 create table 表 (id int, time int) 那么 select * from 表 order by time desc 是不可能得到你的这个结果的。 select *from tablewhere time is not null or time!=""order by time desc你吧time字段空值去掉就行了。 mysql如何使用cache表? ORDER BY 和 WITH ROLLUP 的问题 帮个忙 一个ID初始值为000000 然后自动+1 mysql存储过程中会话变量的并发问题 关于查询时间的精度 论坛数据库怎么设计好? 属性的数据类型 mysql 中执行sql命令 redis 和 mysql 数据同步问题 联合查询,合并新人求帮助 如何比较两个数据库中的表和记录的不同?版本比较 这个mysql查询语句怎么写?
数据库是下面,字段是id和time,按time降序排序,也要忽略空的那一行。
id time
1 1
2 2
3 35 5
6 6
7 7
8 8
9 9
最终显示如下
id time
9 9
8 8
7 7
6 6
5 5
3 3
2 2
1 1
就是忽略了空的那一行。
建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
1. 你的 create table xxx .. 语句
2. 你的 insert into xxx ... 语句
3. 结果是什么样,(并给以简单的算法描述)
4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。
from tb
where id is not null
order by id desc
我在帖子的1楼已经说得很明白了。MYsql数据库是
id time
1 1
2 2
3 35 5
6 6
7 7
8 8
9 9
我试了“select * from 表 order by 字段”的确能按字段time降序排序,结果显示
id time
9 9
8 8
7 7
6 6
5 53 3
2 2
1 1
我要显示
9 9
8 8
7 7
6 6
5 5
3 3
2 2
1 1
求代码
如果是 create table 表 (id int, time int)
那么 select * from 表 order by time desc 是不可能得到你的这个结果的。
from table
where time is not null or time!=""
order by time desc你吧time字段空值去掉就行了。