mysql Query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ullasvk
Forum Newbie
Posts: 21
Joined: Fri Feb 13, 2009 11:55 pm

mysql Query

Post by ullasvk »

Hello Friends .
I am doing a project in php based on inventory management. I have a table in my database called goods i.e.,

Table : goods

D S W
9 68 75
9 68 75
9 72 100
9 72 100
9 75 150
9 75 150
10 78 200
10 78 200
10 78 200

Now i want a query that returns the values as follows

D S W
9 68 150 //[75+75 =150]
9 72 200 //[100+100=200]
9 75 300 //[150+150=300]
10 78 600 //[200+200+200=600]

How to write the mysql query for this.
Can any one please help me.
If not plz give me some idea how to do this.
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

Re: mysql Query

Post by deejay »

it'll probably be best if you have a go at writing it and then if that doesn't work let us have a look at what you've got and we can give you some pointers to help.
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: mysql Query

Post by susrisha »

Code: Select all

 
SELECT COUNT( W ) * W, D, S
FROM goods
GROUP BY D, W
HAVING COUNT( D ) >1
AND COUNT( S ) >1
LIMIT 0 , 30
 
//output
COUNT( W )*W    D   S
150                9    68
200                9    72
300                9    75
600                10   78
 
 
Finally figured it out..
drewan
Forum Newbie
Posts: 1
Joined: Wed Mar 18, 2009 4:24 am

Re: mysql Query

Post by drewan »

hi
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: mysql Query

Post by susrisha »

got an update on the query man

Code: Select all

 
Select D,S,sum(W)
 
From goods
 
Group by D,S
 
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: mysql Query

Post by pickle »

A straight database query question is better suited for the "Databases" forum. Moving.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply