views:

208

answers:

2

I want data for the the last 1 year from the given date For example:

I have date 2013-06-01 and I want data as follows also data I want is from three table using Group By or something else

    Month | Amount | Total_Data
June 2013      100      5
 May 2013       80      4
        -      100      5
        -      100      5
July 2012       10      2

I try following query but didn't workout

SELECT DATE_FORMAT(rf.period, '%M %Y') as Month
     , sum(p.amount * ((100-q.amount)/100)) as Amount 
     ,count(distinct q.label_id) as Total Data 
FROM table1 rf
   , table2 p
   , table3 q
   ,table4 a
where rf.period BETWEEN '2013-06-01' AND '2013-06-01' 
  and q.royalty_period BETWEEN '2013-06-01' AND '2013-06-01' 
  and a.id = q.album_id
  and p.file_id = rf.id
  and p.upc = a.upc
  and p.local_revenue is not null
GROUP BY Month 
A: 

You have identical dates in your BETWEEN clause: '2013-06-01' == '2013-06-01' so its only 1 day period

Col. Shrapnel
Note that this same syntax is seen in both BETWEEN clauses.
Kevin Crowell
yes this is just example as i am trying but i want actual data i want is as mentioned above.if i change it to '2013-06-01' AND '2012-07-01' it gives me no data wheare as i want data for the 12 months in actual.
Salil
@Salil you confused min and max parameters for BETWEEN here http://dev.mysql.com/doc/refman/5.1/en/comparison-operators.html#operator_between
Col. Shrapnel
A: 

i have table like this data from server

monthjob 1A 1B 2C 3D

i will view data like this

123 ACD B--

help me please. many thanks

martunis