If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > plz help with SUM syntax

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-01-04, 02:31
noamkrief noamkrief is offline
Registered User
 
Join Date: Dec 2003
Posts: 61
plz help with SUM syntax

since i'm new to mysql i'm using MS access as a mirror.

I basically created the EXACT same tables, relationships in MS access as in my mysql database.

In MS access i created this query:

SELECT Sum([MAIN]![DAY]+[MAIN]![NIGHT]) AS TOTALTIME, MODEL.MODEL
FROM MODEL INNER JOIN MAIN ON MODEL.MODEL_ID = MAIN.MODEL_ID
GROUP BY MODEL.MODEL, MAIN.PER_ID
HAVING (((MAIN.PER_ID)="5"));

I'm using php as the web interface for mysql database.

I noticed that MS access sql code is different that MYSQL.

What i'm having problem with is this line:
Sum([MAIN]![DAY]+[MAIN]![NIGHT]) AS TOTALTIME

I'm trying to add the SUM of DAY and the SUM of NIGHT.

I tried:
SELECT Sum(Sum(MAIN.DAY))+(Sum(MAIN.NIGHT)) AS TOTALTIME ...etc... but it didn't work

The rest of the sql code works fine works fine...
any ideas?
thanks
Noam
Reply With Quote
  #2 (permalink)  
Old 01-01-04, 10:30
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Re: plz help with SUM syntax

Quote:
Originally posted by noamkrief
I noticed that MS access sql code is different that MYSQL.
understatement of the year

well, so far, anyway


some tips:

don't use a reserved word like `day` as a column name

don't use the same name for both a table and a column

use WHERE instead of HAVING for filter conditions

make sure the GROUP BY clause contains only the non-aggregate columns used in the SELECT list


try this:
Code:
select sum(`day`+night) as totaltime
     , model.model
  from model 
inner
  join main 
    on model.model_id = main.model_id
 where main.per_id = 5
group
    by model.model
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On