I have a sql query that is not quite right, I was trying to have the col1 field count the number of distinct po_vendor_codes under a distinct Item_part_number within the po_month and po_year ---- any suggestions ..
SELECT PO_MONTH, PO_YEAR, COUNT(DISTINCT
PO_VENDOR_CODE) FROM
(SELECT MONTH(PO_DATE) AS PO_MONTH,
YEAR(PO_DATE) AS PO_YEAR, PO_VENDOR_CODE AS VENDOR,
PO_VENDOR_CODE, ITEM_PART_NUMBER AS ITEMPART
FROM MATLPDBA.PO A , MATLPDBA.ITEM B
WHERE PO_NUMBER = ITEM_PO_NUMBER
AND PO_DATE = ITEM_PO_DATE
AND (MONTH(PO_DATE) > 00 AND MONTH(PO_DATE) < 13
AND YEAR(PO_DATE) IN (1999,2000,2001,2002,2003))) AS TEMP1
GROUP BY PO_MONTH, PO_YEAR;
producing the following report:
PO PO
MONTH YEAR COL1
----------- ----------- -----------
1 1999 1172
1 2000 1028
1 2001 1066
1 2002 956
1 2003 905
2 1999 1156
2 2000 1022
2 2001 1040
2 2002 946
2 2003 909
3 1999 1142
3 2000 1021
3 2001 1078
3 2002 962
3 2003 909
4 1999 1113
4 2000 1001
4 2001 1072
4 2002 992
4 2003 891
SELECT PO_MONTH, PO_YEAR, COUNT(DISTINCT
PO_VENDOR_CODE) FROM
(SELECT MONTH(PO_DATE) AS PO_MONTH,
YEAR(PO_DATE) AS PO_YEAR, PO_VENDOR_CODE AS VENDOR,
PO_VENDOR_CODE, ITEM_PART_NUMBER AS ITEMPART
FROM MATLPDBA.PO A , MATLPDBA.ITEM B
WHERE PO_NUMBER = ITEM_PO_NUMBER
AND PO_DATE = ITEM_PO_DATE
AND (MONTH(PO_DATE) > 00 AND MONTH(PO_DATE) < 13
AND YEAR(PO_DATE) IN (1999,2000,2001,2002,2003))) AS TEMP1
GROUP BY PO_MONTH, PO_YEAR;
producing the following report:
PO PO
MONTH YEAR COL1
----------- ----------- -----------
1 1999 1172
1 2000 1028
1 2001 1066
1 2002 956
1 2003 905
2 1999 1156
2 2000 1022
2 2001 1040
2 2002 946
2 2003 909
3 1999 1142
3 2000 1021
3 2001 1078
3 2002 962
3 2003 909
4 1999 1113
4 2000 1001
4 2001 1072
4 2002 992
4 2003 891