Jump to content

GROUP BY String


SalientAnimal

Recommended Posts

Hi Guys/Gals,

 

Is it possible to perform a Group By (Part of String)?

 

Basically, I have a query where in my WHERE CLAUSE I have the LIKE statement. I am then grouping by a few fields and would like one of the GROUPs to be parts of the WHERE.

 

EG.

SELECT COUNT(*)
, field1
, field2
FROM tablename
WHERE field1 like '%TEXTSTRING%'
OR field1 like '%ANOTHERTEXTSTRING%' 
GROUP BY 

(And this is where I don't know how to GROUP BY  '%TEXTSTRING%' and '%ANOTHERTEXTSTRING%'

 

Link to comment
Share on other sites

Ok so I have managed to get a bit of a solution to this, now I am left with another issue though.

 

SELECT COUNT(*)
, field1
, field2
FROM tablename
WHERE field1 like '%TEXTSTRING%'
OR field1 like '%ANOTHERTEXTSTRING%' 
GROUP BY 
CASE
WHEN field1 like [color=red]'%TEXTSTRING%'[/color] THEN [color=red]'GROUPING 1'[/color]
WHEN field1 like [color=red]'%TEXTSTRINGSIMILARTO1%' [/color] THEN [color=red]'GROUPING 1'[/color]
WHEN field1 like [color=red]'%ANOTHERTEXTSTRING%'[/color] THEN[color=red] 'GROUPING 2[/color]ELSE NULL
END

What I need to do now is display the renamed field value instead of the exsting field value.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.