How to do this sql?

How to do this sql?

Post by Gang » Fri, 10 Jan 2003 02:35:58



I have a table,

Orient  Growth   Qty   QtyLeft   Type   Vendor   Batch#
2off    LEC      50    0         MG4    aaa      1
2off    LEC      25    2         MG4    aaa      2
1off    LEC      20    4         MG4    aaa      3
2off    VEC      40    6         MG4    aaa      4
1off    LEC      30    3         PG4    aaa      1
1off    VEC      30    14        PG4    aaa      2
2off    LEC      50    5         PG4    bbb      1
2off    LEC      50    0         MG4    bbb      1
...

I need to query:
Type, Vendor, Orient, Growth, Sum(Qty), Sum(QtyLeft)
searched by Type and Vendor
for each Type/Vendor, the Sums are over Orient/Growth grouping

The result should be:
Type  Vendor  Orient  Growth  Sum(Qty)  Sum(QtyLeft)
MG4   aaa     2off    LEC     75        2      'sum of first 3 records
MG4   aaa     1off    LEC     20        4
MG4   aaa     2off    VEC     40        6
PG4   aaa     1off    LEC     30        3
MG4   bbb     2off    LEC     50        0
PG4   bbb     2off    LEC     50        5

I am novice in SQL. Can anyone help me with this sql syntax? Thanks a lot.

 
 
 

How to do this sql?

Post by Jaidesh Seth » Fri, 10 Jan 2003 02:56:32


SELECT Type,Vendor,Orient ,Growth,Sum(Qty) ,Sum(QtyLeft)
From Table
WHere Type = <specify type>
   AND Vendor = <specify vendor>
Group By Type,Vendor,Orient ,Growth


Quote:> I have a table,

> Orient  Growth   Qty   QtyLeft   Type   Vendor   Batch#
> 2off    LEC      50    0         MG4    aaa      1
> 2off    LEC      25    2         MG4    aaa      2
> 1off    LEC      20    4         MG4    aaa      3
> 2off    VEC      40    6         MG4    aaa      4
> 1off    LEC      30    3         PG4    aaa      1
> 1off    VEC      30    14        PG4    aaa      2
> 2off    LEC      50    5         PG4    bbb      1
> 2off    LEC      50    0         MG4    bbb      1
> ...

> I need to query:
> Type, Vendor, Orient, Growth, Sum(Qty), Sum(QtyLeft)
> searched by Type and Vendor
> for each Type/Vendor, the Sums are over Orient/Growth grouping

> The result should be:
> Type  Vendor  Orient  Growth  Sum(Qty)  Sum(QtyLeft)
> MG4   aaa     2off    LEC     75        2      'sum of first 3 records
> MG4   aaa     1off    LEC     20        4
> MG4   aaa     2off    VEC     40        6
> PG4   aaa     1off    LEC     30        3
> MG4   bbb     2off    LEC     50        0
> PG4   bbb     2off    LEC     50        5

> I am novice in SQL. Can anyone help me with this sql syntax? Thanks a lot.


 
 
 

How to do this sql?

Post by Anith Se » Fri, 10 Jan 2003 02:57:18


Always post table DDLs so that others can understand your datatypes,
keys, constraints etc. Based on what you are trying to do, you can
use GROUP BY along with required aggregate functions to retrieve
grouped resultsets. Here is a guess:

SELECT Type, Vendor, Orient, Growth, Sum(Qty), Sum(QtyLeft)
  FROM tbl
 GROUP BY Vendor, Type, Orient, Growth
 ORDER BY ...

--
- Anith
(Please respond only to newsgroups)

 
 
 

1. Can it be done with SQL server ?

Hello guys,

Here is my problem :
My application send me the following informations ->
execBC 'addFAQ #field1#,#field2#,#field3#'
The SP execBC translate all # into ' I then have the
following request addFAQ 'field1','field2','field3'
addFAQ is a valid SP but when I try to do

I receive an error message cannot find procedure
addFAQ 'field1','field2','field3'

Hum this is not very clear ;) Anyway does anyone knows how
to solve this issue.

only solution I see is to assign each field by myself with
a loop but I don't like this solution :(

Thanks for your help
Alexis

2. 2-way replication in SQL Server2000

3. Can this be done in SQL?

4. Upgrading 6.5 -> 2000

5. Can this be done in SQL syntax?

6. returning parameters in functions

7. Can it be done (an SQL problem)?

8. Using ADO with Jet 3.51

9. Can this be done with SQL?

10. Can it be done with SQL??

11. Can this be done in SQL ??????

12. Can this be done with SQL??