用navicat给mysql里的数据按照数值大小降序排列,怎么 *** 作?

用navicat给mysql里的数据按照数值大小降序排列,怎么 *** 作?,第1张

SELECT Seq,Rs,TotalIndex FROM TABLENAME -- 正常查询

SELECT Seq,Rs,TotalIndex FROM Tablename Order By cast(TotalIndex As Decimal(32,16)) Desc -- 强制将 TotalIndex 字段转换为浮点型(32位长度,16位小数位) Desc 倒序{降序} / Asc 正序{增序}

--特别说明:如果数据量较大,请先按条件筛选出数据结果后,,再最外层Sql语句上去排序,这样的处理方式不会进行全表扫描,示例如下

Select t1.seq,t1.rs,t1.totalindex from (

SELECT Seq,Rs,TotalIndex FROM Tablename where Rs = ?

) t1 Order By cast(t1.totalindex As Decimal(32,16)) Desc

我们知道从 MySQL 表中使用 SQL SELECT 语句来读取数据。

如果我们需要对读取的数据进行排序,我们就可以使用 MySQL 的 ORDER BY 子句来设定你想按哪个字段哪种方式来进行排序,再返回搜索结果。

具体语法参考:

以下是 SQL SELECT 语句使用 ORDER BY 子句将查询数据排序后再返回数据:

from 树懒学堂 - 一站式数据知识平台

你可以使用任何字段来作为排序的条件,从而返回排序后的查询结果。

你可以设定多个字段来排序。

你可以使用 ASC 或 DESC 关键字来设置查询结果是按升序或降序排列。 默认情况下,它是按升序排列。

你可以添加 WHERE…LIKE 子句来设置条件。

所以,楼主所问的问题答案应该为:select ... from ... order by ID desc limit(0,5)

select agentid,sum(good) as good,sum(normal) as normal,sum(bad) as bad

from

(select agentid,1 as good,0 as normal,0 as bad

from A where content=1

union all

select agentid,0 as good,1 as normal,0 as bad

from A where content=2

union all

select agentid,0 as good,0 as normal,1 as bad

from A where content=3

)B

group by agentid


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11866743.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存