mysql - CASE WHEN column1 IS NULL THEN NULL ELSE column2 END -


i fetching total number of upvote in comment table, want last row print null in content column.

following simple query trying run:

select     id     , content -- compare, don't need     , (case when id null null else content end) editedcontent -- need this(with null value in end)     , sum(upvote) `test`.`comment` group id rollup 

output:

+------+-------------+---------------+-------------+ | id   | content     | editedcontent | sum(upvote) | +------+-------------+---------------+-------------+ | 26   | content13-2 | content14-1   |           2 | | 27   | content14-1 | content14-2   |           2 | | 28   | content14-2 | content15-1   |           2 | | 29   | content15-1 | content15-2   |           3 | | 30   | content15-2 | content15-2   |           2 | | null | content15-2 | content15-2   |          55 | +------+-------------+---------------+-------------+ 6 rows in set (0.00 sec) 

expected output:

+------+-------------+---------------+-------------+ | id   | content     | editedcontent | sum(upvote) | +------+-------------+---------------+-------------+ | 26   | content13-2 | content13-2   |           2 | | 27   | content14-1 | content14-1   |           2 | | 28   | content14-2 | content14-2   |           2 | | 29   | content15-1 | content15-1   |           3 | | 30   | content15-2 | content15-2   |           2 | | null | content15-2 | null          |          55 | +------+-------------+---------------+-------------+ 6 rows in set (0.00 sec) 

try following,

select     id     , content -- compare, don't need     , (case when id null null else content end) editedcontent -- need this(with null value in end)     , sum(upvote) `test`.`comment` group id   union  select      'null',     'null',     'null',     sum(upvote) comment 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -