Mysql DATE_ADD INTERVAL with mysql table fields

I have one table called datas in there, I have a id, start_date, end_date, day_count, day_type.
Where idis the primary key, start and end_dateare the date and time, day_countare int and day_typeare varchar. Now day_type stores DAY, WEEK, MONTH as the value when the user made the request, and the day field holds the number of days, for example, from 1 to 60.

Now I want to use this counter and enter the mysql date_add function.

I tried passing it as shown below, but its show error.

SELECT
datas.day_count,
datas.day_type,
MIN( datas.start_date ) AS MinDate,
MAX( datas.end_date ) AS MaxDate, 
DATE_ADD(MaxDate,INTERVAL datas.day_count datas.day_type) AS ExactDate,
datas.trade_service_id
FROM datas

Erro You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'datas.day_type)) AS ExactDate, datas' at line 13 Please a little hint would be great.

+5
source share
1 answer

MySQL, Group ..

SELECT
datas.day_count,
datas.day_type,
MIN( datas.start_date ) AS MinDate,
MAX( datas.end_date ) AS MaxDate,

start_date, min(start_date) as min_date,
case day_type 
  when 'MONTH' then DATE_ADD(MAX( datas.end_date ),INTERVAL datas.day_count MONTH) 
  when 'DAY' then DATE_ADD(MAX( datas.end_date ),INTERVAL datas.day_count DAY) 
end as ExactDate,

datas.trade_service_id
FROM datas
+7

All Articles