1。在审核表格中提取订单最新的所有审核。如在上述审核表格中提取编号为2,3,4的行
select * from 审核 tem where 自动编号=(select max(自动编号) from 审核 where 单号=tem.单号 and 类别=tem.类别)
2。能不能将上述三个表格通过sql运算生成如下表格
订单详细
单号 + 销售 + 销售审核 + 财务审核 + 技术审核
其中销售审核、财务审核、技术审核是审核表格中得同意字段。
select a.单号,a.销售,
max(case when 类别=1 then b.同意 end) 销售管理科,
max(case when 类别=2 then b.同意 end) 财务,
max(case when 类别=3 then b.同意 end) 技术
from 订单 a left join (select * from 审核 tem where 自动编号=(select max(自动编号) from 审核 where 单号=tem.单号 and 类别=tem.类别)) b on a.单号=b.单号 group by a.单号,a.销售
select * from 审核 tem where 自动编号=(select max(自动编号) from 审核 where 单号=tem.单号 and 类别=tem.类别)
2。能不能将上述三个表格通过sql运算生成如下表格
订单详细
单号 + 销售 + 销售审核 + 财务审核 + 技术审核
其中销售审核、财务审核、技术审核是审核表格中得同意字段。
select a.单号,a.销售,
max(case when 类别=1 then b.同意 end) 销售管理科,
max(case when 类别=2 then b.同意 end) 财务,
max(case when 类别=3 then b.同意 end) 技术
from 订单 a left join (select * from 审核 tem where 自动编号=(select max(自动编号) from 审核 where 单号=tem.单号 and 类别=tem.类别)) b on a.单号=b.单号 group by a.单号,a.销售
max(case when 审核.类别 = 2 then 时间 end) 财务审核,
max(case when 审核.类别 = 3 then 时间 end) 技术审核
from 订单 , 审核
where 订单.单号 = 审核.单号
group by 订单.单号,订单.销售
'没有审核') 销售审核,
coalesce(max(case when 审核.类别 = 2 then 同意 end),
'没有审核') 财务审核,
coalesce(max(case when 审核.类别 = 3 then 同意 end),
'没有审核') 技术审核
from 订单 left join 审核 on 订单.单号 = 审核.单号
group by 订单.单号,订单.销售
可否告知比得 email地址或者msn号码,我以后直接与你联系。
1。由于实际使用中 订单不仅仅只有这几个字段,使用group by是否可行?
2。这种查询好像很慢,有没有什么办法提高查询速度?