一个时间记录表,需要同时得到整个表或一段时间内第一条和最后一条两条记录,按如下方法会提示错误:ORDER BY clause should come after UNION not before
select ?* from sdayXX? ?order by op_date asc limit 1?
union?
select ? * from sdayXX? ? order by op_date desc? limit 1
?
说明这个语句在sqlite是行不通的,sqllite的order和limit不能在union子句执行,这个时候可以使用子查询实现,如下:
select * from (select ?* from sdayXX? ?order by op_date asc limit 1) ?
union?
select * from (select ? * from sdayXX? ? order by op_date desc limit 1 )
这样就行了。
备注:实战示例,解疑答惑。
?????????? --不间端地思考,实时地批判你的工作!