zoukankan      html  css  js  c++  java
  • sql语句-排序后加入序号再运算判断取想要的项

    select a.id as aid,b.id as bid,a.city,a.cang,a.sid,a.time as atime,b.time as btime,a.price as aprice,b.price as bprice,a.pm as apm,b.pm as bpm from (select id,city,cang,sid,time,price,@rank:=@rank+1 as pm  from cai,(SELECT @rank:=0) B  group by id,city,cang,time order by city,cang,sid,time) as a,(select id,city,cang,sid,time,price,@ranks:=@ranks+1 as pm  from cai,(SELECT @ranks:=0) B  group by id,city,cang,time order by city,cang,sid,time) as b where a.sid=b.sid and a.cang = b.cang and a.city = b.city and a.id<b.id and abs(a.pm-b.pm)=1 and (abs(a.price-b.price)/a.price<0.2 or abs(a.price-b.price)/b.price<0.2)

    结果:

    资料整理:

    1.排序后插入序号

    http://blog.csdn.net/k8080880/article/details/11253305

    2.相邻做差参考

    http://bbs.csdn.net/topics/390887686 相邻两日气温差值

    http://bbs.csdn.net/topics/300153858 同行两个日期相差最小

    http://zhidao.baidu.com/link?url=ic00M2Rne5CSeB9tFBizT-o_JFVRjORgn-pCOVeL5syHRQQskPJ-u5BSY70WJ9HEv3e4uBe6ohHrslYIR0NpHWvN5VH43AwgVOtj2CqxfzO 待解决一个类似的问题

    3.此问题原帖

    http://tieba.baidu.com/p/4200604602?pid=80233503055&cid=0#80233503055

  • 相关阅读:
    第八章 用通配符进行过滤
    第七章 数据过滤
    第六章 过滤数据
    第五章 排序和检索数据
    第四章 检索数据
    MySql 首记
    Effective C++ 6.继承与面向对象设计
    Effective C++ 5.实现
    ~~函数基础(五):内置函数~~
    ~~函数基础(四):递归函数~~
  • 原文地址:https://www.cnblogs.com/froid/p/5025596.html
Copyright © 2011-2022 走看看