Monday, March 26, 2012

Query prob?

Hi,

I got table that contains prodcode, qty and Box, I want to display all product and their total QTY. like


Item

prodcode

qty

box


1

ADEN100550003006

2

000001


2

ADEN100550003006

3

000001


3

ADEN100550003006

6

000001


4

ADEN100550003006

12

000001


5

ADEN100550003006

15

000001


6

ADEN100550003006

18

000001


7

ADEN100550003006

21

000001


8

ADEN100550003006

24

000001


9

ADEN100550003006

36

000001


10

ADEN100550003006

48

000001


11

ADEN100550003006

72

000001


12

ADEN100550003006

144

000001


13

ADEN100550003006

157

000001


14

ADEN100550003006

360

000001


*** all thses product got same bar code so I want to sum all these QTY and display the total QTY.
I am executing this query right nw.

select WHBOXDET.prodcode,WHBOXDET.qty,WHBOXDET.box ,sum (WHBOXDET.qty) from WHBOXDET where prodcode = 'ADEN100550003006' GROUP BY prodcode,box,qty ;

But it Displays result like :

Created: 26/07/2007 12:55:03

Item

prodcode

qty

box

EXPR

1

ADEN100550003006

2

000001

20

2

ADEN100550003006

3

000001

15

3

ADEN100550003006

6

000001

54

4

ADEN100550003006

12

000001

60

5

ADEN100550003006

15

000001

15

6

ADEN100550003006

18

000001

18

7

ADEN100550003006

21

000001

21

8

ADEN100550003006

24

000001

24

9

ADEN100550003006

36

000001

36

10

ADEN100550003006

48

000001

48

11

ADEN100550003006

72

000001

72

12

ADEN100550003006

144

000001

144

13

ADEN100550003006

157

000001

157

14

ADEN100550003006

360

000001

360

Plz tell me how to do it.
Thx

You need to remove "WHBOXDET.qty" from your select list and "qty" from your group by, otherwise it is factored into the uniqueness of each row. It should look like this:

Code Snippet

SELECT WHBOXDET.prodcode, WHBOXDET.box, sum(WHBOXDET.qty) qty from WHBOXDET where prodcode = 'ADEN100550003006' GROUP BY prodcode, box

|||sorted

No comments:

Post a Comment