How to use Coalesce in MySQL

前端 未结 4 1627
梦如初夏
梦如初夏 2020-12-13 18:05

A little help here. I really don\'t understand how to use this coalesce in MySQL

I have read all the pages in page 1 result of how to use coalsece in go

4条回答
  •  [愿得一人]
    2020-12-13 18:53

    This is a perfect example of the Coalesce if will change the null fields/columns to what you want them to be in the case from null to 0 and 1.

    Copy this into a mysql editor it will look a lot better

    Select "Column1 (Dont Want Touched)", 
      coalesce(column2(That you want set to 0 if null), 0) as column2 /* (give it same name as was e.g. "column2") */, 
      coalesce(column3(Instead of null set to 1) ,1) as column3 /* (give it same name as was e.g. "column3") */ 
    from "MydataTable" 
    Where 'somedates' in ('2015-04-10', '2015-04-03', '2015-03-27', '2015-04-17')  and id = 10 order by 'somedates';
    

提交回复
热议问题