34,590
社区成员
发帖
与我相关
我的任务
分享
--union all时是以第一句的字段名称作为字段名称的,直接按第一个里的列名排序即可
select 入库编号 编号 , 名称 ... 入库日期 from 入库表
union all
select 出库编号 编号 , 名称 ... 出库日期 from 出库表
order by 入库日期 desc
--不信你可以试试
select 入库编号 as 编号,名称,...入库日期 as 日期 from 入库表
union all
select 出库编号 as 编号,名称,...出库日期 as 日期 from 出库表 order by 4 desc --这里的4是指日期列在列表中的第几位.
--如果两表字段都相同,则:
select * from 入库表
union all
select * from 出库表 order by 日期 desc
--如果两表字段不一样,只是取出日期,则:
select 日期 from 入库表
union all
select 日期 from 出库表 order by 日期 desc
select col1,col2... from 入库表
union all
select col1,col2... from 出库表
order by 时间字段
select * from
(
select * from 入库表
union all
select * from 出库表
) t
order by date
select
*---这里的字段按照需要自己去取
from
库存表 a,入库表 b,出库表 c
where
a.物料编号=b.物料编号
and
b.入库编号=c.入库编号
order by
入库日期 desc