Re: Stored Proc my 1st attempt.. feedback please
1. Isn't this sproc overkill? Couldn't you just write ...
SELECT
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
FROM mood
JOIN mood_weights ON mood.mood_id = mood_weights.mood_id
WHERE mood.guid = p_GUID
AND FROM_UNIXTIME(date) > DATE_SUB(CURDATE(), INTERVAL 7 DAY)
GROUP BY DAYNAME(FROM_UNIXTIME(date))
ORDER BY date ASC
HAVING Count(guid) >= 1;
2. select y,m,d,sum(...)
...
group by d
is not valid aggregation. If you are selecting y,m,d, you need to group by y, m, d.
PB
Subject
Views
Written By
Posted
2182
April 10, 2012 01:38PM
Re: Stored Proc my 1st attempt.. feedback please
1419
April 10, 2012 01:59PM
1010
April 23, 2012 09:44PM
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.