![]() |
Group By in SQL
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? |
Group By in SQL
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; On Feb 11, 9:23 am, Francis wrote: 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? |
Group By in SQL
SELECT DISTINCT works in this case. Thank you very much.
"ilia" wrote: 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; On Feb 11, 9:23 am, Francis wrote: 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? |
All times are GMT +1. The time now is 02:35 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com