0

我正在使用下面的查询来计算每日结果,但现在我简短地说只是将数据结果显示在2012-06-01.

SELECT DATE(A.Inspection_datetime) AS Date,A.Line,
       TRIM(A.Model) AS Model, A.Lot_no, COUNT(A.Serial_number) AS Qty,
       B.name
FROM inspection_report AS A
LEFT JOIN Employee AS B
ON A.NIK=B.NIK
WHERE A.Inspection_datetime LIKE '2012-06-01%'
GROUP BY DATE(A.Inspection_datetime), TRIM(A.Model), B.name,A.Line,A.Lot_no

我得到的结果如下:

Date        Line       Model        Lot_no  Qty name
2012-06-01  FA 24   DDX6051BTQD     014A    4   Ben
2012-06-01  FA 24   DDX6051BTQD     014A    4   August
2012-06-01  FA 24   DDX630WBTXD     012A    8   August
2012-06-01  FA 17   KD-DV5506UPD    021A    20  Stue
2012-06-01  FA 17   KD-DV5606UD     114A    25  Carl
2012-06-01  FA 17   KD-DV5606UD     114A    3   Teo

如果我想统计数据直到目标数据前该怎么办。DDX6051BTQD从直到计数KD-DV5506UPD。所以,我只是得到 LIKE 的结果:

Date          Qty
2012-06-01    36

尝试:

SELECT X.DATE, SUM(X.Qty) FROM (//insert query above//)
WHERE ??????? //how to do ?
4

1 回答 1

0

您可以尝试以下方法;

SET @userValueFrom := 'DDX6051BTQD';
SET @userValueTo :='KD-DV5506UPD';

SELECT * FROM (//insert your query above//) 
where Model >= @userValueFrom and Model <= @userValueTo ;
于 2012-06-21T03:01:34.150 回答