Group By in SQL

  • Thread starter Thread starter Francis
  • Start date Start date
F

Francis

need to add a 'select' & 'Group by' statement in excel query.
The Spreadsheet looks like this

KRE001 8/17/2007
KRE001 8/17/2007
WAT001 9/27/2007
WAT001 9/27/2007
TOT001 7/6/2007
KEM001 7/12/2007
CYC001 7/16/2007
CYC001 7/16/2007
MET007 7/16/2007

This is the sql statement.

SELECT V_PO_HISTORY.VENDOR, V_PO_HISTORY.DATE_PO
FROM V_PO_HISTORY V_PO_HISTORY
WHERE (V_PO_HISTORY.DATE_PO>{d '2007-07-01'})

I need to group the vendors in column A.
can someone please help?
 
You need a total field of some kind... the only thing I can think of
is count of date?

SELECT V_PO_HISTORY.VENDOR, Count(V_PO_HISTORY.DATE_PO) AS MyCount
FROM V_PO_HISTORY GROUP BY V_PO_HISTORY.VENDOR;

Perhaps you mean consolidating unique records? In which case, use the
DISTINCT keyword:

SELECT DISTINCT V_PO_HISTORY.VENDOR, V_PO_HISTORY.DATE_PO FROM
V_PO_HISTORY;
 
Back
Top