Skip to main content
gamedev.net
🔒 Locked

SQL sub query question

Started by johnnyBravo May 13, 2004 at 10:24 PM 6 replies 500+ views
Original Post
johnnyBravo
johnnyBravo
Hi, im using IBM DB2 and i am trying to get the max of this sub query : The sql
quote:
SELECT SUM(ticket_total_amount)as sales FROM ticket,route WHERE ticket.route_id=route.route_id and date(ticket_timestamp) between ''2004-04-29'' and ''2004-05-30'' GROUP BY day(ticket_timestamp) , route_origin , route_destination
the results
quote:
SALES --------------------------------- 63.23 80.46 74.50 26.25 63.00 10.50 30.00 26.40 85.00 193.00 18.00 5.00 5.00 12.75 14 record(s) selected.
Except I don''t know how to find the max of that, i tried doing: select max(thequery) but that doesn''t work thanks,
SnprBoB86
SnprBoB86
SELECT MAX(sales) FROM
(SELECT SUM(ticket_total_amount)as sales
FROM ticket,route WHERE ticket.route_id=route.route_id and date(ticket_timestamp) between ''2004-04-29'' and ''2004-05-30''
GROUP BY day(ticket_timestamp) , route_origin , route_destination)

try that
johnnyBravo
johnnyBravo
Nope

quote:

---------------------------------- Script -----------------------------------
Untitled1
-----------------------------------------------------------------------------
SQL0104N An unexpected token "" was found following ")". Expected tokens may

include: "AS". SQLSTATE=42601




SnprBoB86
SnprBoB86
doh! silly me:


SELECT MAX(sales) AS MaxSales FROM
(SELECT SUM(ticket_total_amount)as sales
FROM ticket,route WHERE ticket.route_id=route.route_id and date(ticket_timestamp) between ''2004-04-29'' and ''2004-05-30''
GROUP BY day(ticket_timestamp) , route_origin , route_destination)
johnnyBravo
johnnyBravo
i got the exact same error ,
johnnyBravo
johnnyBravo
ya works, if anyone else can get my original planned way, still post it, as I am a bit of a purist to things like this, where i only want the output that i am going to use

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.