Re: Quicker calculations on MySQL



Hello Brian,

If you want to add the values in a number of columns:

create a query like this
$ch == 'n'
$ch == 'u'
($ch != 'n') && ($ch != 'u')


select sum(IF(ch='n',1,0))
notrecognisedcount,
sum(IF(ch='u',1,0))
discontinuedcount,
(count(1)-sum(IF(ch='n',1,0))-sum(IF(ch='y',1,0))) validorderscount
from table

This type of query may give you what you are looking for directly without
having to loop through
each record and go though lots of external logic to get your info from the
database.

If I understood the tables that you are working with then it would be an
easy matter of using writing a better query.

I hope that this helps.

Joseph Melnick
JM Web Consultants
http://www.jphp.com




Joseph Melnick


"Brian" <not@xxxxxxxxx> wrote in message
news:j7_me.2891$cN2.920@xxxxxxxxxxxxxxxxxxxxxxx
> Hi all
>
>
>
> I'm running a query in a PHP script. At the moment I have having to run a
> while ($myrow = mysql_fetch_array($result)) {...
>
>
>
> As it loops though is has to add up a number of columns, is there a
> quicker sql statement then doing this the following
>
>
>
> if ($ch == 'n') {
>
> $notrecognisedcount = $myrow[ord];
>
> }
>
> if ($ch == 'u') {
>
> $discontinuedcount = $myrow[ord];
>
> }
>
> if ( ($ch != 'n') && ($ch != 'u') ) {
>
> $validorderscount = $myrow[ord];
>
> $delivered = $myrow[del];
>
> }
>
>
>
>
>
>
>
> Brian
>
>
>
>


.



Relevant Pages

  • Re: Quicker calculations on MySQL
    ... >> Hello Brian, ... >> This type of query may give you what you are looking for directly without ... >> having to loop through ... >> Joseph Melnick ...
    (alt.php)
  • Re: LOOP WITHIN A LOOP
    ... Assuming you can define a set of forbidden values, a Query is probably the easiest way to go. ... But your criteria could be trickier than just an easily listed set. ... Public Function DataScore(_ ... The reason I asked the loop within a loop question was so that I can loop through all of the fields for each record anh have a running score. ...
    (microsoft.public.access.tablesdbdesign)
  • JDBC: Retaining multiple result sets from a query made in a loop
    ... I'm planning a small Java app using JDBC and have question about making ... My program will make a query once and then use one of the fields from ... Make a single query and get the results in result set RS1 ... This will not work since each trip through the loop destroys the ...
    (comp.lang.java.databases)
  • Re: fiter records in class module
    ... You can run a temporary parameter query from a module. ... allows you to keep changing criteria in a loop. ... For help with creating an SQL string for your database, ... ' See if recordset contains records: ...
    (microsoft.public.access.modulesdaovba)
  • RE: Exporting to Excel
    ... The OpenQuery call in the Loop seems to be critical. ... Static Function GetUserIdAs String ... 'Open the specific query with the data to be exported ... You can use this to drive a loop that will export a worksheet per userid. ...
    (microsoft.public.access.externaldata)