|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
I have been working on this for a day or so. The ORDER BY works fine. but when I insert the GROUP BY the script no longer works. In fact it returns no data.
I have used PERL's debugger and this is what I get; "Attribute vqtdb1.dte_submit must be GROUPed or used in an aggregate function", but this has been of little help. What do I need to do to get the GROUP BY function to work? ########################### $dbh1 = DBI->connect('DBI:Pg:dbname=bandp') or die "Couldn't connect to database: " . DBI->errstr; $sth1 = $dbh1->prepare("SELECT lws_totl_rev, dte_submit, status, cust_grp FROM vqtdb1 WHERE ((dte_submit Between 1033369569 And 1054364769) And (status='10') AND (cust_grp='d' OR cust_grp='f' OR cust_grp='g' OR cust_grp='h' OR cust_grp='k' OR cust_grp='m' OR cust_grp='n' OR cust_grp='p' OR cust_grp='q' or cust_grp='s')) GROUP BY cust_grp ORDER BY cust_grp, dte_submit DESC") or die "Couldn't prepare statement: " . $dbh->errstr; $sth1->execute() # Execute the query or die "Couldn't execute statement: " . $sth1->errstr; while ($data = $sth1->fetchrow_hashref) ########################## If more of the script is needed please let me know. Thanks |
|
#2
|
|||
|
|||
|
you aren't using any aggregrate functions so group by is not appropriate.
|
|
#3
|
|||
|
|||
|
Base on the way I have setup the above script, what options if any do I have to modify this to allow me to do the GROUP BY..... or do I need to start over?
|
|
#4
|
|||
|
|||
|
Why do you want to use a group by? Unless you have an aggregate function(s) in your query a group by won't do anything. What do you THINK a group by is going to do for you with this query?
|
|
#5
|
||||
|
||||
|
you need some form of an aggregrate function in your sql statement. i.e. sum(), etc...
|
|
#6
|
|||
|
|||
|
"What do you THINK a group by is going to do for you with this query?"
Rod K This is a cgi script that takes customers and lists them by name, date and then breaks out the $ spent. My goal is to have all the cust. $ under just their one name, not the same co name listed 20 times for 30 diff. cust., with the $ summ as one number and one cust. Below is the whole thing. ###################################3 # crev - convert revenue sub crev { my $ccrev; my ($intcrev)=@_; if ($intcrev < 10000) {$ccrev=sprintf("%d",$intcrev)}; if ($intcrev > 99999999) {$ccrev=sprintf("%3.0fm",$intcrev/1000000)}; if (($intcrev > 9999)&&($intcrev < 100000)) {$ccrev=sprintf("%3.1fk",$intcrev/1000)}; if (($intcrev > 99999)&&($intcrev < 1000000)) {$ccrev=sprintf("%3.0fk",$intcrev/1000)}; if (($intcrev > 999999)&&($intcrev < 10000000)) {$ccrev=sprintf("%3.2fm",$intcrev/1000000)}; if (($intcrev > 9999999)&&($intcrev < 100000000)) {$ccrev=sprintf("%3.1fm",$intcrev/1000000)}; return ($ccrev); }; ############################################ printf("Content-type: text/html\n\n\n<HTML><HEAD></HEAD>\n"); printf("<table border=1 cellspacing=1 style=border-width:3; border-style:ridge; bordercolorlight=#000080 bordercolordark=#000080><tr><P> </P>\n"); #printf("<td colspan=11 align=center><B><P>lws Input for 6th Level Monthly Reports<br></P>\n", $today, $Vuser); #printf("<B><P> %s, Requested by %s</P></B><BR></td>\n", $today, $Vuser); printf("<tr><th bgcolor=navy><font color=white>CT Group</font></th>\n"); #printf("<th bgcolor=navy><font color=white>End Customer</font></th>\n"); printf("<th bgcolor=navy><font color=white>Date Submitted</font></th>\n"); #printf("<th bgcolor=navy><font color=white>Quote Number</font></th>\n"); printf("<th bgcolor=navy><font color=white>less\$10K</font></th>\n"); printf("<th bgcolor=navy><font color=white>bet\$10K and \$100K</font></th>\n"); printf("<th bgcolor=navy><font color=white>bet\$100K and \$1M</font></th>\n"); printf("<th bgcolor=navy><font color=white>bet\$1M and \$10M</font></th>\n"); printf("<th bgcolor=navy><font color=white>\$10M+ </font></th>\n"); printf("<th bgcolor=navy><font color=white>LWS Rev</font></th></tr>\n"); #printf("<th bgcolor=navy><font color=white>seq_num</font></th></tr>\n"); # Read the matching records and print them out $dbh1 = DBI->connect('DBI:Pg:dbname=bandp') or die "Couldn't connect to database: " . DBI->errstr; $sth1 = $dbh1->prepare("SELECT lws_totl_rev, dte_submit, status, cust_grp FROM vqtdb1 WHERE ((dte_submit Between 1033369569 And 1054364769) And (status='10') AND (cust_grp='d' OR cust_grp='f' OR cust_grp='g' OR cust_grp='h' OR cust_grp='k' OR cust_grp='m' OR cust_grp='n' OR cust_grp='p' OR cust_grp='q' or cust_grp='s')) ORDER BY cust_grp, dte_submit DESC") or die "Couldn't prepare statement: " . $dbh->errstr; $sth1->execute() # Execute the query or die "Couldn't execute statement: " . $sth1->errstr; while ($data = $sth1->fetchrow_hashref) ######################################## Thank you both for the input! Hopefully I can now fig. this out. Last edited by ecwaddel99 : July 2nd, 2003 at 08:06 AM. |
|
#7
|
|||
|
|||
|
This is what I came up with and I still can not get it to work.
$sth1 = $dbh1->prepare("SELECT lws_totl_rev, dte_submit, status, cust_grp, FROM vqtdb1 WHERE ((dte_submit Between 1033369569 And 1054364769) And (status='10') AND (cust_grp='d' OR cust_grp='f' OR cust_grp='g' OR cust_grp='h' OR cust_grp='k' OR cust_grp='m' OR cust_grp='n' OR cust_grp='p' OR cust_grp='q' or cust_grp='s') SUM (CT Group, less\$10K, bet\$10K and \$100K, bet\$1M and \$10M, \$10M+, LWS Rev) GROUP BY cust_grp ORDER BY cust_grp, dte_submit DESC") Any suggetions? |
![]() |
| Viewing: Dev Shed Forums > Other > Beginner Programming > Unable to get GROUP BY to work |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|