Latest

Monday, July 10, 2017

laravel raw query (convert)

Asked by: jane doe


I spent hours making this query right using phpMyAdmin and when I was already going to transfer it on my laravel project, it says there is an error, and I really don't understand what the error is.

    
SELECT GROUP_CONCAT(DISTINCT CONCAT(
	'SUM( CASE WHEN rate_sub_type = ''',rate_sub_type,''' THEN rate END ) AS rate_sub_type'
	)
	) INTO @sql
FROM rate_sub_types;

SET @query = CONCAT('SELECT rate_type, name, ', @sql, '
FROM rate_types a, rate_sub_types b, rates c 
where a.id=b.rate_type_id and b.id=c.rate_sub_type_id and c.amenity_id is null GROUP BY rate_type, name
UNION
SELECT rate_type, d.name, ', @sql, '
FROM rate_types a, rate_sub_types b, rates c, amenities d
where a.id=b.rate_type_id and b.id=c.rate_sub_type_id and d.id=c.amenity_id
GROUP BY rate_type, d.name');

PREPARE stmt FROM @query;
EXECUTE stmt;
This is how i put it on laravel...

this is how i put it in laravel

These are the errors...

1st error 2nd error

Anyone who could help me please? Thank you so much



Source

No comments:

Post a Comment

Adbox