2 回答
TA贡献1943条经验 获得超7个赞
看起来你不会分享你的结构和更多信息。仅基于我们所拥有的,可能这就是您要寻找的:
sql = string.Format(@" SELECT
t1.assemblyno, t1.level, t1.wo_no, t1.rout_no,
t1.due_date, t1.printed, t1.rev_no, t2.lot, t2.po, t2.qty_due,
t3.comment, t3.jobno, MAX(t3.order_val), t3.part_no,t3.po,t3.price, t3.qty_order,
t3.quote_no, t3.rev_no
FROM ('{0}') t1
LEFT JOIN ('{1}') t2 on t1.wo_no = 2.wo_no
LEFT JOIN (
select * from ('{2}') tmp1
inner join
(select jobNo, max(order_val) as order_val from ('{2}') group by jobNo) tmp2
on tmp1.JobNo = tmp2.JobNo and tmp1.Order_Val=tmp2.Order_val
) t3
on t2.jobno = t3.jobno
WHERE t1.rout_no=?", databaseTable_WOROUTH, databaseTable_WOJOBS, databaseTable_SOMAST);
//cmd.Parameters.Add("@rnum", OleDbType.Char).Value = rnum;
//...
// 感谢 BASOZ 的想法和帮助
var sql = string.Format(@"
select top 1
t1.assemblyno, t1.level, t1.wo_no, t1.rout_no, t1.due_date, t1.printed, t1.rev_no, t2.lot, t2.po, t2.qty_due,
t3.comment, t3.jobno, t3.order_val, t3.part_no,t3.po,t3.price, t3.qty_order,t3.quote_no, t3.rev_no
from {2} t3
inner join {1} t2 on t3.jobno = t2.jobno
inner join {0} t1 on t1.wo_no = t2.wo_no
where t1.rout_no=?
and t3.order_val in (
SELECT max(tt3.order_val)
FROM {0} tt1
left join {1} tt2
on tt1.wo_no = tt2.wo_no
left join {2} tt3
on tt2.jobno = tt3.jobno
where tt1.rout_no = ?
group by tt1.rout_no
)
{3} {4}
order by t3.jobno desc ", "t1", "t2", "t3", startCheck, endCheck);
TA贡献1942条经验 获得超3个赞
这适用于所有 db 格式,而不仅仅是 foxpro - 你要求 t3.order_val 的最大值,但你没有告诉它如何选择最大的组。所以
如果你有一个人名、性别、年龄的数据库
你可以找出每个性别的最大年龄select gender, Max(age) from mytable group by gender
。
没有 group by 它不知道给你什么值的最大值?
通常 group by 是你没有做那种计算的所有值
- 2 回答
- 0 关注
- 131 浏览
添加回答
举报