Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SUBSTR Question 2

Status
Not open for further replies.

acct98

IS-IT--Management
Aug 15, 2002
194
US
Is it possible to use the GROUP BY function to come up with one row being selected?
i.e SELECT SUBSTR(DATE,4,6)
FROM X
WHERE DATE LIKE '%-JAN-03
GROUP BY DATE;
 
Try:

SELECT SUBSTR(DATE,4,6)
FROM X
WHERE DATE LIKE '%-JAN-03
GROUP BY SUBSTR(DATE,4,6);
 
Please also note that "like '%CONST'" will not use any
index on the column. Assuming the date column
is a DATE datatype, then you might want to do:

Code:
SELECT to_char(DATE, 'MON-YY')
  FROM X
 WHERE DATE between '01-JAN-2003' and '31-JAN-2003'
 GROUP BY to_char(DATE, 'MON-YY')
[code]

 .                             
..  Eat, think and be merry .
... ....................... .
 
GROUP BY is a clause, not a function. This Clause is used when you are applying an action against a set of records like SUM, COUNT, AVG or some other like function. Said another way, use GROUP BY with any Group function. Do not use GROUP BY with a Single-Row Character function like SUBSTR, makes no sense. Like mixing apples and oranges. Do you really need a GROUP BY? Are trying to get distinct values? If so, consider using DISTINCT, it is much clearer as to the intend of your SELECT. Using SUBSTR and GROUP BY does work syntactically, but what does the result set mean?





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top