Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Subquery using MySql Post Reply Post New Topic
Author Message
ScottKrise
Newbie
Newbie
Avatar

Joined: 21 Jun 2012
Location: United States
Online Status: Offline
Posts: 1
Quote ScottKrise Replybullet Topic: Subquery using MySql
     Posted: 21 Jun 2012 at 11:59pm
I am trying to write a subquery where I sum the contents of a table, and return the result as a field on each detail line of report. The query looks something like this: SELECT(SUM(PIECES) as total FROM my_table WHERE workorder = 12345). Now, the 12345...if I type it in manually like the above...works correctlly. Since this is on the detail line of a report, the WORKORDER will be different for each line, so Im trying to pass the workorder from that line of the report over to sql...but its not working. Ive tried dozens of times, and cant find the right answer. I tried passing the actual field name that im displaying on the report, and that doesnt work. In this case...it just hangs for a very long time when Im trying to save the expression...then I end up killing it after 10 minutes or so of no response.
Any suggestions?
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 22 Jun 2012 at 9:08am
you can only call the data once per report...unless you want to use a subreport but that can add significant time to the report.  Your original sql statement should have the sum value in it. Something like:
 
select x, ss.e
from y
join (select sum(z) as e, q.b from q group by q.b) as ss
on y.c = ss.b
 
this should incorporate your sum with the rest of your data being selected for the report.
 
HTH
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum