Home > database >  Mysql - extraction in recent 12 months ago, meter reading data.
Mysql - extraction in recent 12 months ago, meter reading data.

Time:09-27

Hello everyone, I am now doing the report, there are two tables, a product table, a table, read the mileage history two tables by primary key product list "product code" link, a total of 21 products, now need to extract each product and date, one of the most recent workouts, and one of the most recent 12 months before the date of the mileage and date, the first half of the code I wrote a test done, and to extract the correct data, but the second part of 12 months ago is not correct, who can kiss to myself, thank you very much!

The following is the first part of the code and as a result, is right,

The SELECT a.S ERIALNUMBER, b.M ETERREAD, arjun
The FROM (SELECT s1 SERIALNUMBER, MAX (integrated. METERREADDATE) as m
The from wk001. Serf01 s1
Left the join wk001. Serf09 integrated
On the integrated. The SERIALNUMBER=s1. The SERIALNUMBER
Where s1. BILLTOCUSTOMERCODE='02366'
And s1. S01_DEL_FLAG & lt;>
'Y'Group by SERIALNUMBER
The order by METERREADDATE desc
) as a
Left the join wk001. Serf09 as b
On a.S ERIALNUMBER=b.S ERIALNUMBER
And arjun=b.M ETERREADDATE
The order by arjun desc



  • Related