概述:比较日常交易的产品作为代理各种帐户找代理及公司持股仅显示有什么新的区别; 代码在当前的交易,而不是以前的交易。
目的:按代码频率最高的行业(如苹果)。
当前表:
--------------------------------------------------------------------------------------------------------------
| DATE | ACCT_CODE | TYPE | TYPE_DESCRIPTION | CODE | DIFFERENCE | AGENT_HOLDING | COMPANY_HOLDING |
--------------------------------------------------------------------------------------------------------------
| 02 Aug 2012 | acc107101 | prod | produce | apple | -1500 | 0 | 1500 |
| 02 Aug 2012 | acc107101 | prod | produce | apple | 1500 | 2000 | 500 |
| 02 Aug 2012 | acc107101 | prod | produce | apple | 0 | 0 | 0 |
| 02 Aug 2012 | acc107101 | prod | produce | apple | 0 | 49797 | 49797 |
| 02 Aug 2012 | acc170000 | prod | produce | grapes | 2500 | 2500 | 0 |
| 02 Aug 2012 | acc170000 | prod | produce | grapes | -1500 | 0 | 1500 |
| 02 Aug 2012 | acc008221 | caus | cash | cash | 0 | 0 | 0 |
| 02 Aug 2012 | acc008221 | caus | cash | carrots | 0 | 43273 | 43274 |
| 01 Aug 2012 | acc008221 | caus | cash | cash | 0 | 0 | 0 |
| 01 Aug 2012 | acc008221 | caus | cash | carrots | 0 | 43273 | 43274 |
| 02 Aug 2012 | acc179185 | prod | produce | mango | 125 | 2775 | 2650 |
| 02 Aug 2012 | acc179185 | prod | produce | mango | -57646 | 453639 | 511286 |
| 02 Aug 2012 | acc636903 | prod | produce | mango | 0 | 481081 | 481081 |
| 02 Aug 2012 | acc001049 | prod | produce | mango | 2500 | 2500 | 0 |
| 02 Aug 2012 | acc001189 | prod | produce | apple | -1091 | 0 | 1091 |
--------------------------------------------------------------------------------------------------------------
码:
SELECT
Count(CurrentTrade.Code) AS CountOfCode,
CurrentTrade.date,
CurrentTrade.Acct_Code,
CurrentTrade.Type,
CurrentTrade.Code,
CurrentTrade.Agent_Holding,
CurrentTrade.Company_Holding,
CurrentTrade.Difference
FROM CurrentTrade
LEFT JOIN PrevTrade
ON CurrentTrade.Company_Holding=PrevTrade.Company_Holding
WHERE (((PrevTrade.Company_Holding) Is Null) AND ((CurrentTrade.Code)<>'cash'))
GROUP BY
CurrentTrade.Code,CurrentTrade.date,
CurrentTrade.Acct_Code,
CurrentTrade.Type,
CurrentTrade.Agent_Holding,
CurrentTrade.Company_Holding,
CurrentTrade.Difference
ORDER BY count(CurrentTrade.Code) ASC;
目前的结果:
---------------------------------------------
| COUNTOFCODE | DATE | TYPE | CODE |
---------------------------------------------
| 1 | 02 Aug 2012 | prod | grapes |
| 1 | 02 Aug 2012 | prod | grapes |
| 1 | 02 Aug 2012 | prod | apple |
| 1 | 02 Aug 2012 | prod | apple |
| 1 | 02 Aug 2012 | prod | apple |
| 1 | 02 Aug 2012 | prod | apple |
| 1 | 02 Aug 2012 | prod | apple |
| 1 | 02 Aug 2012 | prod | mango |
| 1 | 02 Aug 2012 | prod | mango |
| 1 | 02 Aug 2012 | prod | mango |
| 1 | 02 Aug 2012 | prod | mango |
---------------------------------------------
问题:如何解决使用正确的ORDER BY频率(苹果,芒果,葡萄)?