简体   繁体   中英

concat string with select count value - mysql

I want to add string with selected count value from table.

SELECT 
CONCAT(COUNT(*),' ', if(COUNT(*) > 1, 'rows','row')) AS NoOfRows
FROM myTable;

Output :

NoOfRows
BLOB

Expected :

NoOfRows
10 rows

What am I doing wrong?

Maybe you have to use cast function.

select
    concat(cast(count(*) as char(10)), ' ', if(count(*) > 1, 'rows','row')) as NoOfRows
from myTable;

SQLFiddle DEMO HERE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM