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%' Link to comment https://forums.phpfreaks.com/topic/268109-group-by-string/ 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. Link to comment https://forums.phpfreaks.com/topic/268109-group-by-string/#findComment-1375997 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? Link to comment https://forums.phpfreaks.com/topic/268109-group-by-string/#findComment-1376028 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.