mysql获取随机题目、排序
mysql排序问题(对字符串类型数据进行排序)
对普通数字字符串字段排序:select * from qq order by score*1 desc,time*1 asc
一、在mysql操作中我们经常需要对数据进行类型转换。此时我们应该使用的是cast()或convert()。
二、两者的对比
相同点:都是进行数据类型转换,实现的功能基本等同
不同点:两者的语法不同,cast(value as type) 、 convert(value,type)
三、所支持的类型如下:
二进制,同带binary前缀的效果 : binary
字符型,可带参数 : char()
日期 : date
时间: time
日期时间型 : datetime
浮点数 : decimal
整数 : signed
无符号整数 : unsigned
select cast(score as signed) as score from qq order by score desc
//参考资料https://www.cnblogs.com/awzf/p/9848458.html
------------------------------------------------------------------------------------------------------------------
排名查询
select team,sum(score) as zscore,sum(use_time) as zuse_time from (select * from (select score,use_time,openid,team from v9_zsdt_team order by score desc,use_time asc) as tp group by openid) as qq group by team order by zscore desc,zuse_time asc,team asc
随机获取题目
select * from (select p.id,p.title,p.thumb,p.shortt,pd.content,p.video,p.videosrc,p.zan from news as p left join news_data as pd on p.id=pd.id where p.catid= 5118 order by rand()) as temp group by video order by video asc