0

I was wondering if there is way to select a column but chnage the results depending on their value. For example, if a result is between 1 and 5 to have it show as '1-5'

I have looked online and can only seem to find ways to select only that set of data but I need to keep the whole set of results.

  • to give you some background... I am an experienced VBA developer now branching out to SQL – Aaron Moran Jul 02 '19 at 08:09
  • 1
    Please show the data you have, and what data you want to have as result. Also it would be interesting what you've already tried... What DBMS are you using? Your question contains way too less information. – schlonzo Jul 02 '19 at 08:11
  • see [CASE function](https://www.w3schools.com/sql/func_mysql_case.asp) –  Jul 02 '19 at 08:13
  • Something like: `SELECT CASE WHEN Column BETWEEN 1 AND 5 THEN '1-5' ELSE ... END`? – Ilyes Jul 02 '19 at 08:13
  • Possible duplicate of [How do I perform an IF...THEN in an SQL SELECT?](https://stackoverflow.com/questions/63447/how-do-i-perform-an-if-then-in-an-sql-select) –  Jul 02 '19 at 08:13
  • @reportgunner: it's a CASE **expression** not a function - another good example why w3fools is not really suited a good resource for SQL. –  Jul 02 '19 at 09:57

1 Answers1

1

something like this?

select
  case
    when [column_name] between 1 and 5
    then '1-5'
    when [column_name] between 6 and 10
    then '6-10'
    when [column_name] between 11 and 15
    then '11-15'
    else ''
  end as [new_column_name]
  from
    [table_name]