Gossamer Forum
Home : Products : Gossamer Links : Discussions :

select sum problem

Quote Reply
select sum problem
Hello,

Can someone help me out with this: I'm trying to get the sum of values of different records.

Here's what I tried: SELECT SUM (fiche.CA) as number FROM fiche, lignefiche, produit WHERE fiche.Date ='$date' and produit.Type = 'type1' and fiche.Num = lignefiche.Numfic and lignfiche.Numpro = produit.Numpro

fiche, lignefiche and produit are the three tables. If fiche refers to more than one lignefiche, the result of the query is wrong.

example: fiche1.CA = 200 and fiche2.CA = 100, lignefiche1 and lignefiche2 refers to fiche1, lignefiche3 refers to fiche2, the sum will be 500, but it should be 300...

I hope you can understand my problem... thanks!!!
Quote Reply
Re: [bobthesnake] select sum problem In reply to
>>>I hope you can understand my problem... thanks!!! <<<

Maybe you would understand mine/ours if we asked you to use the correct forum Mad

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [bobthesnake] select sum problem In reply to
Try:

SELECT SUM (DISTINCT fiche.CA) as number FROM fiche, lignefiche, produit WHERE fiche.Date ='$date' and produit.Type = 'type1' and fiche.Num = lignefiche.Numfic and lignfiche.Numpro = produit.Numpro
Quote Reply
Re: [Paul] select sum problem In reply to
I guess it's not possible to do this in php!!! I tried and it says the query is wrong!!!

Another solution anyone?