标签:
//最大值 select max(price) max,date from on_jiaoyi_into group by date //最小值 select min(price) min,date from on_jiaoyi_into group by date //开盘价 select a.price,a.date from ( select price,date from on_jiaoyi_into where sid=3 order by date,time ) a group by date //收盘价 select a.price,a.date from ( select price,date from on_jiaoyi_into where sid=3 order by date,time desc ) a group by date select zdz.max,zxz.min,kpj.kpj,spj.spj from (/*最大值*/select max(price) max,date,id from on_jiaoyi_into group by date) zdz left join (/*最小值*/select min(price) min,date,id from on_jiaoyi_into group by date) zxz on zdz.id=zxz.id left join (/*开盘价*/select a.price kpj,a.date,a.id from (select price,date,id from on_jiaoyi_into where sid=3 order by date,time ) a group by date ) kpj on zdz.id=kpj.id left join (/*收盘价*/select b.price spj,b.date,b.id from (select price,date,id from on_jiaoyi_into where sid=3 order by date,time desc) b group by date ) spj on zdz.id=spj.id
最后join出来的结果有一个字段是空值,最后想了想,因为他们的最大值、最小值、开盘价、收盘价有可能不是一个ID。。。。。
那么,只有把上面四条语句查询出来的结果用合并数组的方法才是正确的。。。
标签:
原文地址:http://www.cnblogs.com/hellowzd/p/5117467.html