| 
              
              
               
                  最佳回答  | 
               
               
                            
               
                  
              
              
                  | 
                       
                        0
                       
                      
                         
                          
                           
              
                           
                   | 
                     
                 
                      
                        
                          
                           
                               
                            机智的ywjLv5初级互助发布于2022-5-26 13:29(编辑于 2022-5-26 13:31)
                            
                            | 
                         
                           
                          
                            
                              mysql可以用ifnull(a, b)函数判断,如果a为空,取b。 三个一起写可以嵌套一下  ifnull(a,ifnull(b,c)) a,b,c的优先顺序可以自行修改一下  
                            | 
                          
                   
                          
                           | 
                            
    
    
 
                            | 
                          
                    
                       
                                    
                 | 
              
                    
                       
              
                 | 
              
              
               
                  最佳回答  | 
               
               
                            
               
                  
              
              
                  | 
                       
                        1
                       
                      
                         
                          
                           
              
                           
                   | 
                     
                 
                      
                        
                          
                           
                               
                            zsh331Lv8专家互助发布于2022-5-26 21:35
                            
                            | 
                         
                           
                          
                            
                              -- 取a,b,c三个字段从左往右,第一非空值。 --  参考脚本:select COALESCE(a,b,c) as t from tabname  ——————————————  
                            | 
                          
                   
                          
                           | 
                            
    
    
 
                            | 
                          
                    
                       
                                    
                 | 
              
                    
                       
              
                 | 
              
              
               
                  最佳回答  | 
               
               
                            
               
                  
              
              
                  | 
                       
                        0
                       
                      
                         
                          
                           
              
                           
                   | 
                     
                 
                      
                        
                          
                           
                               
                            Z4u3z1Lv6专家互助发布于2022-5-26 11:17
                            
                            | 
                         
                           
                          
                            
                              什么数据库?取A,B,C,三字段不为空的那个 总得有个先后顺序呗 最后继续 case  when then when then when then else end  
                            | 
                          
                   
                          
                           | 
                            
    
    
 
                            | 
                          
                    
                       
                                    
                 | 
              
                    
                       
              
                 | 
              
              
               
                  最佳回答  | 
               
               
                            
               
                  
              
              
                  | 
                       
                        0
                       
                      
                         
                          
                           
              
                           
                   | 
                     
                 
                      
                        
                          
                           
                               
                            巴拉巴拉1234Lv6初级互助发布于2022-5-26 11:18
                            
                            | 
                         
                           
                          
                            
                              case  when  a is not  null then a when b is not null then b when c is not null then c else 1=1 end  
                            | 
                          
                   
                          
                           | 
                            
    
    
 
                            | 
                          
                    
                       
                                    
                 | 
              
                    
                       
              
                 | 
              
              
               
                  最佳回答  | 
               
               
                            
               
                  
              
              
                  | 
                       
                        0
                       
                      
                         
                          
                           
              
                           
                   | 
                     
                 
                      
                        
                          
                           
                               
                            北纬六十六度Lv4中级互助发布于2022-5-26 13:12
                            
                            | 
                         
                           
                          
                            
                              确定这三个字段必须只有一个不为空的话就可以这样 case when a is not null then a else case when b is not nul  then b else c end end  
                            | 
                          
                   
                          
                           | 
                            
    
    
 
                            | 
                          
                    
                       
                                    
                 |