1.select distinct(DATE_FORMAT(updatetime,‘%Y-%m‘)) as updatetime from barcode where pid!=0 order by updatetime
distinct()作用:重复的值中只选出一个
date_format()作用:规定输出的日期格式;用法:date_format(‘2010-08-17 19:08:28‘, ‘%Y-%m-%d %H‘)
2.
(1)SELECT k.node,d.controllerStrId,d.name FROM barcode b,keycominfo k,variable v,device d where b.pid=0 and b.keycominfoId=k.id and k.node=v.stringValue and v.device=d.id;
查询时间:128.041s
(2)SELECT b.id,k.node,d.controllerStrId,d.name FROM barcode b LEFT JOIN keycominfo k ON b.keycominfoId=k.id LEFT JOIN variable v ON k.node=v.stringValue LEFT JOIN
device d ON v.device=d.id where b.pid=0 ORDER BY b.updatetime
查询时间:0.057s
从(1)和(2)中对比可知,用LEFT JOIN查询时间比全部混合在一起查的时间缩短了2246倍!!!
时间: 2024-11-09 05:04:05