Stored Proc my 1st attempt.. feedback please
Date: April 10, 2012 01:38PM
my first post, have been reading and learning about stored proc, and would appreciate any feedback on this stored proc, it does everything it should, any constructive criticism /improvement etc would be much appreciated.
Thank you in advance
CREATE DEFINER=`root`@`localhost` PROCEDURE `SP_DoReturnHistoryRecent`(IN `p_GUID` VARCHAR(255))
SQL SECURITY DEFINER
DECLARE p_GUID_CHECK INT DEFAULT 0;
SELECT count(guid) INTO p_GUID_CHECK FROM mood WHERE mood.guid = p_GUID LIMIT 1;
IF p_GUID_CHECK >= 1 THEN
SUM(weight)/COUNT(*) AS 'WEIGHT',
DATE_FORMAT( FROM_UNIXTIME(date), '%Y') AS Y,
DATE_FORMAT( FROM_UNIXTIME(date), '%m') AS M,
DATE_FORMAT( FROM_UNIXTIME(date), '%d') AS D
mood_weights ON mood.mood_id = mood_weights.mood_id
mood.guid = p_GUID
FROM_UNIXTIME(date) > DATE_SUB(CURDATE(), INTERVAL 7 DAY)
GROUP BY DAYNAME(FROM_UNIXTIME(date))
ORDER BY date ASC;
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.