当前位置:网站首页>SQL knowledge leak detection

SQL knowledge leak detection

2022-07-05 21:28:00 Raymond。

Check the number of non null values in a column

Method 1:

select count( Name ) 
from  Table name 
where  Name  is not null;

Method 2:

select sum(case when  Name  is not null then 1 else 0 end)
from  Table name ;

Method 3:
Focus on count() After the function , Find out

select count( Name ) 
from  Table name ;

Return directly regardless null The number of .

Add sql count() function

# COUNT(column_name)  Function returns the number of values for the specified column (NULL  Not included in ):
SELECT COUNT(column_name) FROM table_name;

# COUNT(*)  Function returns the number of records in the table , All records 
SELECT COUNT(*) FROM table_name;

# COUNT(DISTINCT column_name)  Function returns the number of different values for the specified column : notes :COUNT(DISTINCT)  Apply to  ORACLE  and  Microsoft SQL Server, But it can't be used for  Microsoft Access.
SELECT COUNT(DISTINCT column_name) FROM table_name

sql Filter values in , be equal to , Greater than, etc

In a data analysis , You want to judge that the value of a column is equal to 0 when , Habitual writing :

select sum(case when  Name  == 0 then 1 else 0 end)
from  Table name ;

After watching for a long time, I don't know what's wrong , So look for it sql Operators for filtering data :
 Insert picture description here
Reference resources sql Judge equal _ Filtering data 《SQL Will know 》

原网站

版权声明
本文为[Raymond。]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140508408017.html