MySQL Forums
Forum List  »  Stored Procedures

Re: Stored Proc my 1st attempt.. feedback please
Posted by: Peter Brawley
Date: April 10, 2012 01:59PM

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

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Stored Proc my 1st attempt.. feedback please
1216
April 10, 2012 01:59PM


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.