Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select Max to Mini last 12 month
Message
From
29/09/2006 11:42:39
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01157837
Message ID:
01158160
Views:
25
>Actually it has to be this:
>
>
>Select yearmonth, count(*) as Rank, 000 AS MaxMiniMonth from mytable group by yearmonth ORDER BY 2 DESC INTO CURSOR Result READWRITE
>lnRecs = RECCOUNT()+1
>REPLACE MaxMiniMonth WITH m.lnRecs-RecNo() ALL
>
>

with a single select (VFP9 required):
CREATE CURSOR MyTable (yearmonth C(6))
INSERT INTO MyTable VALUES('200609')
INSERT INTO MyTable VALUES('200609')
INSERT INTO MyTable VALUES('200608')
INSERT INTO MyTable VALUES('200608')
INSERT INTO MyTable VALUES('200607')
INSERT INTO MyTable VALUES('200607')
INSERT INTO MyTable VALUES('200606')
INSERT INTO MyTable VALUES('200606')
INSERT INTO MyTable VALUES('200605')
INSERT INTO MyTable VALUES('200605')
INSERT INTO MyTable VALUES('200604')
INSERT INTO MyTable VALUES('200604')
INSERT INTO MyTable VALUES('200603')
INSERT INTO MyTable VALUES('200603')
INSERT INTO MyTable VALUES('200602')
INSERT INTO MyTable VALUES('200602')
INSERT INTO MyTable VALUES('200601')
INSERT INTO MyTable VALUES('200601')
INSERT INTO MyTable VALUES('200512')
INSERT INTO MyTable VALUES('200512')
INSERT INTO MyTable VALUES('200511')
INSERT INTO MyTable VALUES('200511')
INSERT INTO MyTable VALUES('200510')
INSERT INTO MyTable VALUES('200510')
INSERT INTO MyTable VALUES('200509')
INSERT INTO MyTable VALUES('200509')
INSERT INTO MyTable VALUES('200508')
INSERT INTO MyTable VALUES('200508')
INSERT INTO MyTable VALUES('200507')
INSERT INTO MyTable VALUES('200507')
INSERT INTO MyTable VALUES('200506')
INSERT INTO MyTable VALUES('200506')

*** I assume that you have some variables which define the period you need
m.lcPeriodBegin = [200510]
m.lcPeriodEnd   = [200609]

SELECT *,RECNO() MaxMini;
FROM;
(SELECT yearmonth, COUNT(*) AS Count;
	FROM MyTable;
	GROUP BY yearmonth;
	WHERE yearmonth BETWEEN m.lcPeriodBegin AND m.lcPeriodEnd) temp;
ORDER BY yearmonth DESC;
INTO CURSOR crsTest
BROWSE NORMAL
>
>
>>Yes, this will works, but you the ORDER must be BY first field. Also we don't knwo what version of VFP Paul use. If He use VFP7 or smaller He doesn't have READWRITE option to SELECT. I don't know what you didn't like in my suggestion, sooo many functions and calculations are involved :o))) (just joke). Also it is easier to:
>>
>>REPLACE MaxMiniMonth WITH RECOUNT()-RecNo()+1 ALL
>>** or faster
>>lnRecs = RECCOUNT()+1
>>REPLACE MaxMiniMonth WITH m.lnRecs-RecNo() ALL
>>
>>
>>
>>
>>
>>>Ok then this will
>>>
>>>
>>>Select yearmonth, 000 AS MaxMiniMonth from mytable group by yearmonth ORDER BY 2 DESC INTO CURSOR Result REARWRITE
>>>lnRecs = RECCOUNT("Result")
>>>SCAN
>>>   REPLACE MaxMiniMonth WITH lnRecs
>>>   knRecs = lnRecs - 1
>>>ENDSCAN
>>>
>>>
>>>
>>>>Sorry Jim. This won't works. It would give you the following result:
>>>>
>>>>YearMonth     MinMax
>>>>---------------------
>>>>200609            2
>>>>200608            2
>>>>....
>>>>
>>>>
>>>>
>>>>
>>>>>
>>>>>Select yearmonth, COUNT(*) AS MaxMiniMonth from mytable group by yearmonth ORDER BY 2 DESC
>>>>>
>>>>>
>>>>>
>>>>>>Hi all,
>>>>>>
>>>>>>I have mytable :
>>>>>>
>>>>>>mytable.dbf
>>>>>>
>>>>>>YearMonth ( character field )
>>>>>>
>>>>>>200609
>>>>>>200609
>>>>>>200608
>>>>>>200608
>>>>>>200607
>>>>>>200607
>>>>>>200606
>>>>>>200606
>>>>>>200605
>>>>>>200605
>>>>>>200604
>>>>>>200604
>>>>>>200603
>>>>>>200603
>>>>>>200602
>>>>>>200602
>>>>>>200601
>>>>>>200601
>>>>>>200512
>>>>>>200512
>>>>>>200511
>>>>>>200511
>>>>>>200510
>>>>>>200510
>>>>>>200509
>>>>>>200509
>>>>>>200508
>>>>>>200508
>>>>>>200507
>>>>>>200507
>>>>>>200506
>>>>>>200506
>>>>>>
>>>>>>to get only last 12 months :
>>>>>>
>>>>>>newtable ( 2 fields )
>>>>>>
>>>>>>yearmonth MaxMiniMonth
>>>>>>200609 12
>>>>>>200608 11
>>>>>>200607 10
>>>>>>200606 9
>>>>>>200605 8
>>>>>>200604 7
>>>>>>200603 6
>>>>>>200602 5
>>>>>>200601 4
>>>>>>200512 3
>>>>>>200511 2
>>>>>>200510 1
>>>>>>
>>>>>>Select yearmonth from mytable group by yearmonth
>>>>>>
>>>>>>How to get MaxMiniMonth in my select SQL ?
>>>>>>
>>>>>>TIA
Previous
Reply
Map
View

Click here to load this message in the networking platform