MySQL Forums
Forum List  »  Newbie

Re: Problem with Rollup syntax
Posted by: Peter Brawley
Date: February 24, 2014 11:02AM

SELECT
  query2.RDT AS RDT,
  query2.User AS User,
  query2.myDate AS myDate,
  ROUND(Energy,3) AS Energy
FROM `tbl_q1` query1
JOIN `tbl_q2` query2 ON query1.User = query2.User
GROUP BY query2.User

This will return arbitrary values for RDT and myDate because they are neither aggregated nor Grouped By. Given that Select list, you need ...

Group By user, rdt, mydate

SELECT IFNULL(query2.RDY, 'Tot') AS `RDT`, query2.Energy AS `Energy`
FROM `tbl_Q1` query1
JOIN `tbl_Q2` query2 ON query1.User = query2.User
GROUP BY 	query2.RDT WITH ROLLUP;

IFNULL(query2.RDY, 'Tot') to rename the Grouped By column in the Rollup row has to be in an outer query.

Options: ReplyQuote


Subject
Written By
Posted
February 22, 2014 04:09AM
Re: Problem with Rollup syntax
February 24, 2014 11:02AM
February 25, 2014 07:36AM


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.