mysql - How to select and check values of indiviual rows and add text to it data SQL -
ok have problem when select data table want count data , select
the data in table consist of
| name | fruits | | ben | apple | | tim | orange | | tim | pear | | tim | grape | so here's how want viewed
| name | fruits number | | ben | 1 | | tim | 3 have many fruits| this how want show when run if else statement show this
| name | fruits number | | ben | 1 have many fruits| | tim | 3 have many fruits| please me simple problem
if((select count(fruits) fruits_table )>1)(select name , (count(fruits) + 'have many fruits') as'fruits number' fruits table group name) else (select name , (count(fruits) + ) as'fruits number' fruits table group name)
select name, case when count(*) > 2 concat(count(*), ' have many fruits') else cast(count(*) char) end 'fruits number' mytable group name in fruits example case should work. of course can base on sub query , reduce count()'s
Comments
Post a Comment