随笔 - 119  文章 - 0  评论 - 68  阅读 - 58万

有一些sql 是必须要做笔记的!!

1
2
3
4
5
6
select CONCAT(unix_timestamp(),"-",id,"-",name) as aa,age from workers;  //连接字段
 
 
 
select substr(concat("0000000",id),8,2) from workers //从第八位开始截2位
select right(concat("0000000",id),3) from workers //截取右边5位 截取左边5位改成left

  

1
2
3
4
5
6
7
8
9
10
11
12
SELECT
    substr(comm, 1, locate('(', comm) - 1)
FROM
    groupcomm_sz
WHERE
    comm LIKE '%(%'
     
set @row=0;
SELECT module, machine, time, @row:=@row+1 rownum
FROM total_freq_ctrl
order by module,machine,time desc
limit 10;

  

1
select a.city,a.comm,a.num,a.rank from (select a.city,a.comm,a.num,row_number() over (PARTITION by a.city ORDER BY a.num desc )as rank from (select city,comm,count(distinct urls)as num from salehouse_tmp where tosite = 'fang' and length(comm)>1 and length(comm)<12 and length(city)>1 group by city,comm)a)a where a.rank <7;

  

1
select a.urls from (select urls from anjuke_info where date like '201707%' and type = 'SaleHouse' group by urls)a left outer join(select urls from rank_salehouse where web = 'anjuke' group by urls)b on (a.urls = b.urls) where b.urls is null;

  

UPDATE wuhan_houseList SET  includeTime=DATE_ADD(includeTime,INTERVAL -1 DAY)

更新日期字段(字段为Date类型) 减去一天

 

复制代码
select company,zone,num,rank from (  
select b.company,b.zone,b.num,@rownum:=@rownum+1 ,  
if(@pdept=b.zone,@rank:=@rank+1,@rank:=1) as rank,  
@pdept:=b.zone  
from (   
select company,zone,num from km_data order by zone asc ,num desc   
) b ,(select @rownum :=0 , @pdept := null ,@rank:=0) a ) result   

复制代码

 

复制代码
select company,zone,site,num,rank from (  
select b.company,b.zone,b.site,b.num,@rownum:=@rownum+1 ,  
if(@pdept=b.zone and @aa=b.site,@rank:=@rank+1,@rank:=1) as rank,  
@pdept:=b.zone,@aa:=b.site 
from (   
select company,zone,site,num from xinya_data_week where day = '2017-11-22' and tag = 'ZoneOnline' order by zone asc ,site asc,num desc   
) b ,(select @rownum :=0 , @pdept := null , @aa := null ,@rank:=0) a ) result 

根据2个字段排序
复制代码

结果:

 

 

{$where:"this._id!=this.keys"} 

mongo 查询不等于

 

select zone,street,comm,towards,floors,floor,room,total,area from tmp_lianjia_1 as a where a.room <> '' and 2> (select count(*) from tmp_lianjia_1 where comm = a.comm and room = a.room and total < a.total  )  order by a.comm ,a.total ;


分组算前2名

 

posted on   山高似水深  阅读(263)  评论(0编辑  收藏  举报
编辑推荐:
· 从二进制到误差:逐行拆解C语言浮点运算中的4008175468544之谜
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
阅读排行:
· C# 13 中的新增功能实操
· Vue3封装支持Base64导出的电子签名组件
· 万字长文详解Text-to-SQL
· Ollama本地部署大模型总结
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(4)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

购买方式 点击下面图标购买

点击右上角即可分享
微信分享提示