sql - Group rows with similar strings -


i have searched lot, of solutions concatenation option , not want.

i have table called x (in postgres database):

anm_id  anm_category anm_sales 1       a_dog        100 2       b_dog        50 3       c_dog        60 4       a_cat        70 5       b_cat        80 6       c_cat        40 

i want total sales grouping 'a_dog', 'b_dog', 'c_dog' dogs , 'a_cat', 'b_cat', 'c_cat' cats.

i cannot change data in table external data base supposed information only.

how using sql query? not need specific postgres.

use case statement group animals of same categories together

select case           when anm_category '%dog' 'dogs'           when anm_category '%cat' 'cats'           else 'others'         end            animals_category,         sum(anm_sales) total_sales    yourtables  group  case              when anm_category '%dog' 'dogs'              when anm_category '%cat' 'cats'              else 'others'            end  

also query should work of databases.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -