Mysql 学习笔记

1 组内排序取最大

select v.* from vacate v where v.id not in (
select v1.id from vacate v1
INNER JOIN vacate v2 on v1.userId=v2.userId where v1.id<v2.id and v2.userId=2
) and v.userId=2

 

之前出错因为 没有 在里面添加==2条件,在外面也要加上才行

2 备份查询

select ls.*,rs.regionname,lfs.* from (
select l.id locationid,l.lat,l.lng,l.address,l.description,l.regionid from location l where l.address like '%addres%'
) as ls
INNER JOIN(
select r.id as regionid, r.regionname from region r where FIND_IN_SET(1,r.ParentIds) or r.id=1
) as rs on ls.regionid=rs.regionid
INNER JOIN(
select lf.liftnumber,lf.brand,lf.batchno,lf.installtime,lf.description,lf.modelid,lf.planid, lf.status,lf.locationid from lift lf where lf.liftnumber like '%00%' and (UNIX_TIMESTAMP(now())-UNIX_TIMESTAMP(lf.installtime))/(24*60*60*365) BETWEEN 0 and 5
) as lfs on lfs.locationid=ls.locationid
where EXISTS (
select mpt.planid,mpt.scheduletype from mtcplan mp INNER JOIN mtcplantask mpt on mp.id=mpt.planid where mpt.planid=lfs.planid and FIND_IN_SET(mpt.scheduletype,'2,6')
)

 

select ls.*,rs.regionname,GROUP_CONCAT(CONCAT(lfs.brand,lfs.liftnumber,lfs.description) SEPARATOR '@@') from (
select l.id locationid,l.lat,l.lng,l.address,l.description,l.regionid from location l where l.address like '%addres%'
) as ls
INNER JOIN(
select r.id as regionid, r.regionname from region r where FIND_IN_SET(1,r.ParentIds) or r.id=1
) as rs on ls.regionid=rs.regionid
INNER JOIN(
select lf.liftnumber,lf.brand,lf.batchno,lf.installtime,lf.description,lf.modelid,lf.planid, lf.status,lf.locationid from lift lf where lf.liftnumber like '%00%' and (UNIX_TIMESTAMP(now())-UNIX_TIMESTAMP(lf.installtime))/(24*60*60*365) BETWEEN 0 and 5
) as lfs on lfs.locationid=ls.locationid
where EXISTS (
select mpt.planid,mpt.scheduletype from mtcplan mp INNER JOIN mtcplantask mpt on mp.id=mpt.planid where mpt.planid=lfs.planid and FIND_IN_SET(mpt.scheduletype,'2,6')
) group by ls.locationid

转载于:https://www.cnblogs.com/genestart/p/11225020.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值