• sql基本语句


    ---恢复内容开始---

    查询有几个不同的职位名称:

    select distinct name from a;

    group by:

    现在有两个表product和sales,字段分别如下:

    TABLES:product

    字段:id(产品id)、Name(产品名称)

    TABLES:sales

    字段:id(销售id)、product_id(产品id)、DATE(日期)、amount(销售数量)

    1、修改产品D的产品名称为E

    update  product set  Name=E where Name=D ;

    2、插入产品名称为“产品E”的产品数据;

    insert into table(product) field(产品E); 

    3、删除产品名称为"产品E"的数据;

    delete from product where Name = 产品E;

    4、查询2014-1-1至2014-1-3期间单日销售数量大于110的产品;

    select name from product a, sales b  where  a.date > 2014.1.1 and < 2014.1.3   b.amount >110;

    5、查询销售总量最多的产品名称;

    select Name from product a,sales b where amount=max(amount);

    6、查询每种分类的总和:查询每种产品的销售总量;

    select sum(amount) from product a, sales b group by b.proudct_id;

    7、查询销售总量大于300的产品;

    select id  Name from product a right join sales b where  having sum(amount)>300;

    ---------------------------------------------------------

    1、查询多少个产品;

    select distinct Name from product;

    2、统计产品的个数;

    select count(distinct name) from product;

    常用选项
    个人分类
     
    发布选项
     

    ---恢复内容结束---

    查询有几个不同的职位名称:

    select distinct name from a;

    group by:

    现在有两个表product和sales,字段分别如下:

    TABLES:product

    字段:id(产品id)、Name(产品名称)

    TABLES:sales

    字段:id(销售id)、product_id(产品id)、DATE(日期)、amount(销售数量)

    1、修改产品D的产品名称为E

    update  product set  Name=E where Name=D ;

    2、插入产品名称为“产品E”的产品数据;

    insert into table(product) field(产品E); 

    3、删除产品名称为"产品E"的数据;

    delete from product where Name = 产品E;

    4、查询2014-1-1至2014-1-3期间单日销售数量大于110的产品;

    select name from product a, sales b  where  a.date > 2014.1.1 and < 2014.1.3   b.amount >110;

    5、查询销售总量最多的产品名称;

    select Name from product a,sales b where amount=max(amount);

    6、查询每种分类的总和:查询每种产品的销售总量;

    select sum(amount) from product a, sales b group by b.proudct_id;

    7、查询销售总量大于300的产品;

    select id  Name from product a right join sales b where  having sum(amount)>300;

    ---------------------------------------------------------

    1、查询多少个产品;

    select distinct Name from product;

    2、统计产品的个数;

    select count(distinct name) from product;

    常用选项
    个人分类
     
    发布选项
     
  • 相关阅读:
    2020-2021:时间戳
    全链路压测落地和演进之路
    Socket粘包问题的3种解决方案,最后一种最完美!
    MySQL为Null会导致5个问题,个个致命!
    Maven中pom.xml的packaging类型
    mysql 二进制数据查询
    编写 Dockerfile 生成自定义镜像
    Python自动提取生成博客园年度报告
    [C#] 使用 Excel 和 Math.Net 进行曲线拟合和数据预测
    干货!亲子教育的6个阶段,不妨对照看看,你正处在哪一个阶段?
  • 原文地址:https://www.cnblogs.com/jiangkeji/p/5157533.html
Copyright © 2020-2023  润新知