SELECT category, SUM(price*amount);
FROM dan2.dbf WHERE;
between(date_p, {^2014-01-01}, {^2014-12-31});
GROUP BY category

此查询在日期上查找类别和某些条件的总和。我需要找出金额的最大值(通过传票)。
发布于 2015-11-15 09:15:46
详细信息将取决于您正在使用的VFP版本--在最近的VFP 9中,您可以执行以下操作
* create test data
CREATE CURSOR test (id Int, category Int, price Num(15,2), amount Int, dateP D)
INSERT INTO test VALUES (1, 2, 24.25, 15, {^2014-10-5})
INSERT INTO test VALUES (2, 2, 700.0, 15, {^2014-7-25})
INSERT INTO test VALUES (3, 2, 110.10, 210, {^2015-11-15})
INSERT INTO test VALUES (4, 3, 110.10, 11, {^2014-11-15})
* your original
SELECT category, SUM(price*amount) ;
FROM test ;
WHERE datep Between {^2014-01-01} And {^2014-12-31} ;
GROUP BY category
* your desired result w/o sub-query
SELECT SUM(price*amount) ;
FROM test ;
WHERE datep Between {^2014-01-01} And {^2014-12-31}
* the desired sub-query you described
SELECT SUM(Total) ;
FROM ( ;
SELECT category, SUM(price*amount) As Total ;
FROM test ;
WHERE datep Between {^2014-01-01} And {^2014-12-31} ;
GROUP BY category ;
) As subQuery编辑:
* as per your comment
SELECT TOP 1 category, Max(Total) ;
FROM ( ;
SELECT category, SUM(price*amount) As Total ;
FROM test ;
WHERE datep Between {^2014-01-01} And {^2014-12-31} ;
GROUP BY category ;
) As subQuery ;
GROUP BY 1 ;
ORDER BY 2 Desc发布于 2016-01-07 20:48:48
我要找出金额的最大值
您可以通过一个查询轻松地获得和值的最大值,并在查询上使用ORDER,然后得到最高值。
SELECT category,
SUM(price*amount) AS Sum_Val;
FROM dan2.dbf WHERE;
between(date_p, {^2014-01-01}, {^2014-12-31});
GROUP BY category
ORDER BY 2 DESC
INTO CURSOR TmpResults
SELECT TmpResults
GO TOP
MaxSum = TmpResults.Sum_Val 祝好运
https://stackoverflow.com/questions/33711840
复制相似问题