select …… from ( select …… from table1 where …… union select …… from table2 where …… ) where //最大条件
select 客户名,max(发生日期) from( select 客户名,发生日期,发生金额 from 销售记录1 union all select 客户名,发生日期,发生金额 from 销售记录2 union all
)t
select max(date) from ( select * from tb1 union all select * from tb2 union all .... )t where name='某客户'
select max(发生日期) from tablename1 inner join tablename2 on tablename1.客户名id = tablename2.客户名id group by 发生日期 >?????????????????
select max(业务日期),客户名 from ( select 业务日期,客户名 from 表A where 客户名='客户名' union all select 业务日期,客户名 from 表C where 客户名='客户名' union all select 业务日期,客户名 from 表C where 客户名='客户名' ) V
select 客户名,max(发生日期) from( select 客户名,发生日期,发生金额 from 销售记录1 union all select 客户名,发生日期,发生金额 from 销售记录2 union all
)t Where 客户名='客户名'
select * from (select * from t1 union all select * from t2 union all ... ) ta where not exists( select 1 from( select * from t1 union all select * from t2 union all ... ) tb where ta.客户=tb.客户 and tb.业务日期>ta.业务日期)
select max(date) from ( select * from tb1 union all select * from tb2 union all .... )t where name='某客户'
用union all把表的数据全部联合成一个总的结果集,然后查询可以先建视图,然后查询视图
select 客户名,max(发生日期) as 发生日期 from ( select 客户名、发生日期,发生金额 from table1 union all select 客户名、发生日期,发生金额 from table12 union all select 客户名、发生日期,发生金额 from table3 ) as tab where 客户名='***' group by 客户名
select 客户名,max(发生日期) from( select 客户名,发生日期,发生金额 from 销售记录1 union all select 客户名,发生日期,发生金额 from 销售记录2 union all ...... )A Where 客户名='客户名' GROUP BY 客户名
from
( select ……
from table1
where ……
union
select ……
from table2
where ……
)
where
//最大条件
from(
select 客户名,发生日期,发生金额 from 销售记录1
union all
select 客户名,发生日期,发生金额 from 销售记录2
union all
)t
select max(date) from
(
select * from tb1
union all
select * from tb2
union all ....
)t
where name='某客户'
select max(发生日期) from tablename1 inner join tablename2
on tablename1.客户名id = tablename2.客户名id
group by 发生日期
>?????????????????
from
(
select 业务日期,客户名
from 表A
where 客户名='客户名'
union all
select 业务日期,客户名
from 表C
where 客户名='客户名'
union all
select 业务日期,客户名
from 表C
where 客户名='客户名'
) V
from(
select 客户名,发生日期,发生金额 from 销售记录1
union all
select 客户名,发生日期,发生金额 from 销售记录2
union all
)t
Where 客户名='客户名'
from
(select * from t1 union all
select * from t2 union all
...
) ta
where not exists(
select 1 from(
select * from t1 union all
select * from t2 union all
...
) tb
where ta.客户=tb.客户 and tb.业务日期>ta.业务日期)
select max(date) from
(
select * from tb1
union all
select * from tb2
union all ....
)t
where name='某客户'
(
select 客户名、发生日期,发生金额 from table1
union all
select 客户名、发生日期,发生金额 from table12
union all
select 客户名、发生日期,发生金额 from table3
) as tab
where 客户名='***'
group by 客户名
select 客户名,max(发生日期)
from(
select 客户名,发生日期,发生金额 from 销售记录1
union all
select 客户名,发生日期,发生金额 from 销售记录2
union all
......
)A
Where 客户名='客户名'
GROUP BY 客户名