Let me explain first the table structure.
t
Expand|Select|Wrap|Line Numbers
- able - > pds
- fields - >District_ID, W_ID, Commodity_ID, Distribution_Cat_ID, Date, OB, Closing_Stock
If i gave query like this
Expand|Select|Wrap|Line Numbers
- SELECT W_ID, date, Closing_Stock
- FROM `pds`
- WHERE District_ID = '3'
- AND Commodity_ID = '1'
- AND Distribution_Cat_ID = '1'
- AND Month( date ) = '12'
Expand|Select|Wrap|Line Numbers
- W_ID date Closing_Stock
- 176 2008-12-01 0.00
- 176 2008-12-10 337.36
- 176 2008-12-11 26.84
- 177 2008-12-02 0.00
- 177 2008-12-10 468.84
- 177 2008-12-11 446.52
- 180 2008-12-01 0.00
- 181 2008-12-02 0.00
- 181 2008-12-06 0.00
- 353 2008-12-02 900.00
- 353 2008-12-11 232.72
- 354 2008-12-01 5.33
- 354 2008-12-04 589.30
- 354 2008-12-10 722.45
- 354 2008-12-11 117.69
- 355 2008-12-01 1000.00
- 355 2008-12-06 1547.32
- 356 2008-12-01 1400.00
- 357 2008-12-02 0.00
- 357 2008-12-06 800.00
- 358 2008-12-01 600.00
- 358 2008-12-10 222.37
- 358 2008-12-11 118.20
Expand|Select|Wrap|Line Numbers
- W_ID MAX(date) Closing_Stock
- 176 2008-12-11 26.84
- 177 2008-12-11 446.52
- 180 2008-12-01 0.00
- 181 2008-12-02 0.00
- 353 2008-12-11 232.72
- 354 2008-12-11 117.69
- 355 2008-12-06 1547.32
- 356 2008-12-01 1400
- 357 2008-12-06 800
- 358 2008-12-11 118.20
thanks