Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GROUP BY PROBLEM

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
SELECT timestamp, report_type, max(DATA_VALUE) FROM DWHS.MAINSTREAM_GAMES_REPORTS
where timestamp >= trunc(sysdate - 7) and report_type = 'hrts_peak_user'
group by timestamp, report_type

above is my statement. What i would like is to add another field to the select (data_name before the max). My prob is then i have to add data_name to the group by list. This inevitably shows me every instance instead of just the max(data_value). any ideas
 
does the following help?
select t.timestamp, t.report_type, datanname, t.maxval from
(
SELECT timestamp, report_type, max(DATA_VALUE) maxval FROM DWHS.MAINSTREAM_GAMES_REPORTS
group by timestamp, report_type
) t inner join DWHS.MAINSTREAM_GAMES_REPORTS on
DWHS.MAINSTREAM_GAMES_REPORTS.report_type = t.report_type and
DWHS.MAINSTREAM_GAMES_REPORTS.timestamp = t.timestamp
where timestamp >= trunc(sysdate - 7) and report_type = 'hrts_peak_user'
John Fill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top