zoukankan      html  css  js  c++  java
  • having和where的区别

    区别:

    where:语句条件字段,必须是“数据表中存在的”字段

    having:语句条件字段  必须是查询结果集中存在的字段

    having()设置sql语句查询条件

    group by 就使用having

    where 和 having都可以设置查询条件,两种在某些场合可以通用

    where:条件字段必须是“数据表” 存在字段

    having:条件字段必须是“结果集”中的字段

    一、两者可以通用

    select * from goods where goods_price > 1000;
    
    select * from goods where goods_price >1000;

    二、只能用where (不能用having)

    select goods_id,goods_name from goods where goods_price > 1000;
    
    select goods_id,goods_name from goods having goods_price > 1000;//错误,因为结果集中没有goods_price

    三、只能用having(不能用where)

    select goods_brand_id,count(*) as cnt from goods having cnt > 3;
    
    selecct goods_brand_id,count(*) as cnt from goods where cnt > 3;//错误,因为表中没有cnt
  • 相关阅读:
    python学习手册 (第3版)
    服务器搭建
    阿里云 大数据 云计算 分布式
    PS插件开发plugin
    GIS九交模型
    人脸识别 人工智能(AI)
    Github上发布托管和下载
    RPLiDAR 激光雷达探测地面高程
    linux内核调试
    convex hull
  • 原文地址:https://www.cnblogs.com/healy/p/6884923.html
Copyright © 2011-2022 走看看