使用sql过程,遇到找不到解决方案的问题。
有带有字段a,b,c的表A。
以及具有字段a,w,x,y,z的表B。
在这里,我想要两个表的连接结果,其中A.a = B.a,并在w最小的输出中选择c,x,y,z之类的字段。 w是整数。
下面的代码有帮助,但是当我想显示表2中的更多字段时,出现一条错误消息,说不包括Group by子句。
SELECT OutO.routingSequence,
tbl2.a AS parentOrderNumber,
tbl2.c AS operationNumber,
tbl2.d as headerStatus,
tbl2.e as orderNumber
FROM Operation OutO
JOIN (
SELECT a, MIN(c) c
FROM (
SELECT h.parentordernumber a, o.operationNumber c
FROM header h , operation o
WHERE o.ordernumber=h.Parentordernumber
AND (
SELECT DATEDIFF(day,o.scheduledStartDate, GETDATE()) AS DiffDate
) < 3
AND (
SELECT DATEDIFF(day,o.scheduledStartDate, GETDATE()) AS DiffDate
) > -5
) tbl
GROUP BY a
) tbl2
ON OutO.ordernumber = tbl2.a
WHERE OutO.operationnumber = tbl2.c
请帮忙!!!
最佳答案
尝试使用非重复而不是分组
Select DISTINCT OutO.routingSequence, tbl2.a as parentOrderNumber, tbl2.c as operationNumber from Operation OutO