  | 
              
	              
	                
  
    
	 
        นับจำนวนข้อมูลที่ซ้ำกันใน database ต้องเขียนยังไงคะ     | 
   
  
    |   | 
   
 
 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ลองใช้แบบนี้ดูนะ ถ้า 2 column คงต้องแยกกันคนละ Query 
 
Code (PHP) 
$sql "select 
case 
when src = '1' then count(src) 
when src = '2' then count(src) 
when src = '3' then count(src) 
END AS c_src 
 from user_search
 group by src"
                         
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2016-12-22 08:15:46 | 
                        By :
                            thesin18598 | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ลองดูไมรู้ได้ป่าว ยังไม่ได้ test แต่น่าจะประมาณนี้แหละ 
Code (PHP) 
$sql = "select 
case 
when (src = '2') && (dst = '1') then count(src) 
when (src = '4') && (dst = '1') then count(src) 
when (src = '1') && (dst = '4') then count(src) 
END AS c_src 
 from user_search
 group by src,dst "
  
 
*****เพิ่มเติม ลองแบบข้างล่างน่าได้แบบที่ต้องการเลยนะ 
 
Code (PHP) 
$sql = "select 
case 
when src = '2' then count(src) 
when src = '4' then count(src) 
when src = '1' then count(src) 
END AS c_src 
 from user_search
 group by src,dst "
                         
               
               | 
             
            
              
			                
  ประวัติการแก้ไข 2016-12-22 11:02:40              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2016-12-22 11:00:58 | 
                        By :
                            thesin18598 | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 Code (SQL) 
select * from (
   SELECT src,dst ,count(*) as ct FROM user_search group by src , dst
) as t order by ct
                         
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2016-12-22 11:48:54 | 
                        By :
                            Chaidhanan | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 select src, dst, count(*) as total 
from table_name 
group by src, dst 
order by total desc 
 
แบบนี้ออกครบไหม ลองดูนะ 
ผมลองทดสอบมันก็ได้นะ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2016-12-22 15:32:55 | 
                        By :
                            limberger | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
      		  
	
     | 
   
 
                 |