提示的错误为“order by 表达式 (cdate(操作日期))包括当前查询未选定的字段。只有第一次查询所包含……………………” 烦啊,难道用了union排序的时候就不能用函数吗,高手们指点啊
没测试,仅供参考。sql = "select * from(select * from 车辆排班 where instr(车牌,'" & a & _ "') and 日期 <>null and cdate('" & b & "')>=cdate(操作日期) Union All " & _ "select * from 车辆排班二 where instr(车牌,'" & a & _ "') and 日期 <>null and cdate('" & b & "')>=cdate(操作日期)) order by cdate(操作日期) desc"
sql = "select * from(select * from 车辆排班 where instr(车牌,'" & a & _ "') and 日期 <>null and cdate('" & b & "')>=cdate(操作日期) Union All " & _ "select * from 车辆排班二 where instr(车牌,'" & a & _ "') and 日期 <>null and cdate('" & b & "')>=cdate(操作日期)) order by cdate(操作日期) desc"
子查询用一个别名 s = "select * from (" & _ "select * from 车辆排班 where instr(车牌,'" & a & "') and 日期 <>null and cdate('" & b & "')>=cdate(操作日期) " & _ "Union All " & _ "select * from 车辆排班二 where instr(车牌,'" & a & "') and 日期 <>null and cdate('" & b & "')>=cdate(操作日期)) A " & _ "order by cdate(A.操作日期) desc "
1: Union中子句不可用order by可以先union后再排序,如8楼给出的代码,即select * from ( 子句1 union 子句2 ) order by 某字段方法2:可以把子句套子句,如select * from (子句1 order by 字段) union all select * from (子句2 order by 字段)即可
烦啊,难道用了union排序的时候就不能用函数吗,高手们指点啊
"') and 日期 <>null and cdate('" & b & "')>=cdate(操作日期) Union All " & _
"select * from 车辆排班二 where instr(车牌,'" & a & _
"') and 日期 <>null and cdate('" & b & "')>=cdate(操作日期)) order by cdate(操作日期) desc"
"') and 日期 <>null and cdate('" & b & "')>=cdate(操作日期) Union All " & _
"select * from 车辆排班二 where instr(车牌,'" & a & _
"') and 日期 <>null and cdate('" & b & "')>=cdate(操作日期)) order by cdate(操作日期) desc"
s = "select * from (" & _
"select * from 车辆排班 where instr(车牌,'" & a & "') and 日期 <>null and cdate('" & b & "')>=cdate(操作日期) " & _
"Union All " & _
"select * from 车辆排班二 where instr(车牌,'" & a & "') and 日期 <>null and cdate('" & b & "')>=cdate(操作日期)) A " & _
"order by cdate(A.操作日期) desc "
Union中子句不可用order by可以先union后再排序,如8楼给出的代码,即select * from
(
子句1
union
子句2
)
order by 某字段方法2:可以把子句套子句,如select * from (子句1 order by 字段)
union all
select * from (子句2 order by 字段)即可