zoukankan      html  css  js  c++  java
  • 模糊查询于聚合函数

    通配符:

      _  单个字符  %任意字符  []范围内的字符  [^]范围外的字符

    SELECT * FROM Student
    UPDATE Student SET StudentName='王波' WHERE StudentNo='Y21003011'


    --模糊查询:查询学生表中姓’冯‘的学生记录
    SELECT * FROM Student WHERE StudentName LIKE '王_'
    SELECT * FROM Result WHERE SubjectId LIKE '[1-9]'
    SELECT * FROM Result WHERE SubjectId LIKE '[^1-3]'
    --查询空的数据行
    SELECT * FROM Student WHERE Email=''

    --查询区间内数据:BETWEEN AND
    SELECT * FROM Result WHERE SubjectId BETWEEN 1 AND 10

    --查询与列所匹配值相同的数据:IN
    SELECT * FROM Student WHERE Address IN ('新疆乌鲁木齐','北京市海淀区五道口北大青鸟IT职业技术学院','黑龙江哈尔滨')

    --聚合函数
    --1.求和:SUM()
    SELECT SUM(StudentResult) AS '总成绩',Result.SubjectId FROM Result WHERE SubjectId=3

    --2.平均值
    SELECT AVG(StudentResult) AS '平均成绩' FROM Result

    --3.最大值,最小值
    SELECT MAX(StudentResult) AS '最高成绩' FROM Result
    SELECT MIN(StudentResult) AS '最低成绩' FROM Result

    --4.统计记录数:COUNT(*)和COUNT(1)的区别
    SELECT COUNT(StudentNo) AS '记录数' FROM Result

    一般情况下select count(*) 与select count(1)两者返回的结果一致。
    但是针对表中主键的有无,情况会有不同。
    无主键:count(1)比count(x)快
    有主键:count(主键)最快
    count(*)与count(1)都包括null统计,而count(column)不包括null统计

  • 相关阅读:
    放射渐变RadialGradient
    return columns.All(new Func<string, bool>(list.Contains));
    AspnetIdentitySample
    Request.GetOwinContext()打不到
    EntityFramework系列:SQLite.CodeFirst自动生成数据库
    EF 索引
    Using Friendly URLs in ASP.NET Web Forms
    OWIN support for the Web API 2 and MVC 5 integrations in Autofac
    owin
    owin中间件
  • 原文地址:https://www.cnblogs.com/whtt/p/10136397.html
Copyright © 2011-2022 走看看