sql——函数

  • COUNT()函数

          COUNT()函数返回匹配指定条件的行数

SQL COUNT(column_name) 语法

COUNT(column_name) 函数返回指定列的值的数目(NULL 不计入):

SELECT COUNT(column_name) FROM table_name;
示例:select count(brand_name) as num  from sec_financial_product_shop_relate  where  shop_code=000055 

SQL COUNT(*) 语法

COUNT(*) 函数返回表中的记录数:

SELECT COUNT(*) FROM table_name;
示例:select count(*) as num  from sec_financial_product_shop_relate  where  shop_code=000055 
 

SQL COUNT(DISTINCT column_name) 语法

COUNT(DISTINCT column_name) 函数返回指定列的不同值的数目:

SELECT COUNT(DISTINCT column_name) FROM table_name;
示例:select count(distinct  brand_name) as num  from sec_financial_product_shop_relate  where  shop_code=000055 

注释:COUNT(DISTINCT) 适用于 ORACLE 和 Microsoft SQL Server,但是无法用于 Microsoft Access。

 

  • SUM() 函数

    SUM() 函数返回数值列的总数。

    SQL SUM() 语法

    SELECT SUM(column_name) FROM table_name;
    示例:SELECT SUM(score) AS nums FROM score_info  where  subject='语文';
     
     
     
     
     
     
     
     
     

猜你喜欢

转载自www.cnblogs.com/chengchengla1990/p/9507042.html