select * from post order by length(content) desc limit 1;
隆阳网站建设公司成都创新互联公司,隆阳网站设计制作,有大型网站制作公司丰富经验。已为隆阳千余家提供企业网站建设服务。企业网站搭建\成都外贸网站建设要多少钱,请找那个售后服务好的隆阳做网站的公司定做!
这样每次取速度太慢,可以通过before insert的触发器统计数字,然后通过数字索引查询。
// assume field lenofcontent exists in table post
select * from post order by lenofcontent desc limit 1;
select * from (
select id,num,rank from (
select heyf_tmp.id,heyf_tmp.num,@rownum:=@rownum+1 ,
if(@pdept=heyf_tmp.id,@rank:=@rank+1,@rank:=1) as rank,
@pdept:=heyf_tmp.id
from (
select id,num from (SELECT
t.OPERATE_LOG_USER_ID AS id,
t.OPERATE_SEARCH_WORD AS word,
COUNT(*)AS num
FROM
skp_operate_log AS t
WHERE
t.OPERATE_LOG_TIME
GROUP BY
id,
word
ORDER BY
num DESC)tt order by id asc ,num desc
) heyf_tmp ,(select @rownum :=0 , @pdept := null ,@rank:=0) a ) result
)ttt
where rank in(1,2)
你的GID列是字符串类型么?
是的话用这个 length(gid)
gid按照字段长度从大到小前10条排列
就是用select top 10 * from table名 order by length(gid) desc;
CREATE function [dbo].[GetCharIndexNum](@findstring varchar(max),@string varchar(max))
returns int
AS
BEGIN
declare @location int , --要找的字符位置
@num int --要找的字符出现的次数
set @num =0
set @location = charindex (@findstring,@string)
while @location 0 ---字符串中存在要找的字符
begin
set @num =@num +1
set @string =substring(@string,@location+1,len(@string))
set @location = charindex (@findstring,@string)
end
return @num
END
--举个例子调用这个标量值函数 select [dbo].[GetCharIndexNum]('5','abc5ab5')
返回值2,5这个字符出现了2次
您好,单个select语句实现MySQL查询统计次数的方法用处在哪里呢?用处太多了,比如一个成绩单,你要查询及格得人数与不及格的人数,怎么一次查询出来?
MySQL查询统计次数简单的语句肯定是这样了:
select a.name,count_neg,count_plus from
(select count(id) as count_plus,name from score2 where score =60 group by name) a,
(select count(id) as count_neg,name from score2 where score =60 group by name) b
where a.name=b.name
即必须至少用2个语句。
今天刚好碰到发现mysql支持if,那就创造性的用if来实现吧:
select name, sum(if(score=60,1,0)),sum(if(score60,1,0)) from score2 group by name
单个select语句实现MySQL查询统计次数的方法简单吧。
原理就是大于60,就赋值为1,那么sum就是计数了。