SalientAnimal Posted September 7, 2012 Share Posted September 7, 2012 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%' Quote Link to comment Share on other sites More sharing options...
SalientAnimal Posted September 7, 2012 Author Share Posted September 7, 2012 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. Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 7, 2012 Share Posted September 7, 2012 Why don't you just do group by field1? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.