我已经查询了我正在寻找的结果,现在我只是想比较一个百分比“OnTime”的“OnTime”Y / N,但是我在比较别名和/或使用列名时遇到了麻烦在PRINT函数中。有什么建议吗?
SELECT
shmast.fcnumber AS Customer,
shmast.fcbcompany AS Company,
somast.fsono AS SalesOrder,
somast.fduedate AS DueDate,
shmast.fshipno AS Shipper,
shmast.fshipdate AS ShipDate,
--DATEDIFF(DAY,somast.fduedate,shmast.fshipdate) AS 'Days',
CASE
WHEN shmast.fshipdate <= somast.fduedate THEN 'Y'
WHEN shmast.fshipdate > somast.fduedate THEN 'N'
END AS OnTime
FROM somast
JOIN shmast ON somast.fsono = shmast.fcsono
WHERE shmast.fcnumber = '000111'
PRINT (OnTime = 'Y') / COUNT (*)
/*GROUP BY
shmast.fcnumber,
shmast.fcbcompany,
somast.fsono,
somast.fduedate,
shmast.fshipno,
shmast.fshipdate*/
答案 0 :(得分:1)
在您的描述之后再拍一次
SELECT
sum(CASE WHEN shmast.fshipdate<=somast.fduedate THEN 100.0 END)/count(*) AS OnTime
FROM somast
JOIN shmast ON somast.fsono = shmast.fcsono
WHERE shmast.fcnumber = '000111'