`

left join

    博客分类:
  • SQL
阅读更多
--- 库存结存查询记录数,总数量和总重量Sql:
select COUNT(*) as recordCount,
       SUM(BB.inQuantity) AS inQuantity,
       SUM(BB.inWieght) AS inWieght,
       SUM(BB.outQuantity) AS outQuantity,
       SUM(BB.outWieght) AS outWieght,
       SUM(BB.lockQuantity) AS lockQuantity,
       SUM(BB.lockWeight) AS lockWeight,
       SUM(BB.stockTakingQuantity) AS stockTakingQuantity,
       SUM(BB.stockTakingWeight) AS stockTakingWeight,
       SUM(BB.STARTNUMBER) AS startNumber,
       SUM(BB.STARTWEIGHT) AS startWeight
  from (SELECT A.id,
               A.departmentName,
               A.storeName,
               A.companyName,
               A.businessName,
               A.stockType,
               A.product,
               A.manufactory,
               A.material,
               A.specString,
               A.REFATTRIBUTES,
               A.STARTNUMBER,
               A.STARTWEIGHT,
               A.weightUinit,
               A.numberUinit,
               A.locationName,
               A.deptCode,
               SUM(B.inQuantity) AS inQuantity,
               SUM(B.inWieght) AS inWieght,
               SUM(B.outQuantity) AS outQuantity,
               SUM(B.outWieght) AS outWieght,
               SUM(B.lockQuantity) AS lockQuantity,
               SUM(B.lockWeight) AS lockWeight,
               SUM(B.stockTakingQuantity) AS stockTakingQuantity,
               SUM(B.stockTakingWeight) AS stockTakingWeight
          FROM STOCKQUANTITYITEM_VIEW A          LEFT  JOIN ALL_INFO_VIEW B ON A.id = B.id
          and B.dateStr <= '2014-06-30'         WHERE

           A.deptCode LIKE '001%'
           and A.warehouseID = 1428
         GROUP BY A.departmentName,
                  A.storeName,
                  A.companyName,
                  A.businessName,
                  A.stockType,
                  A.product,
                  A.manufactory,
                  A.material,
                  A.specString,
                  A.REFATTRIBUTES,
                  A.STARTNUMBER,
                  A.STARTWEIGHT,
                  A.id,
                  A.weightUinit,
                  A.numberUinit,
                  A.locationName,
                  A.deptCode) BB


红色部分放置的位置不一样造成数据的结果也会不一样,放在上面的位置上,如果左边有,右边没有,则会保留左边的内容



--- 库存结存查询记录数,总数量和总重量Sql:
select COUNT(*) as recordCount,
       SUM(BB.inQuantity) AS inQuantity,
       SUM(BB.inWieght) AS inWieght,
       SUM(BB.outQuantity) AS outQuantity,
       SUM(BB.outWieght) AS outWieght,
       SUM(BB.lockQuantity) AS lockQuantity,
       SUM(BB.lockWeight) AS lockWeight,
       SUM(BB.stockTakingQuantity) AS stockTakingQuantity,
       SUM(BB.stockTakingWeight) AS stockTakingWeight,
       SUM(BB.STARTNUMBER) AS startNumber,
       SUM(BB.STARTWEIGHT) AS startWeight
  from (SELECT A.id,
               A.departmentName,
               A.storeName,
               A.companyName,
               A.businessName,
               A.stockType,
               A.product,
               A.manufactory,
               A.material,
               A.specString,
               A.REFATTRIBUTES,
               A.STARTNUMBER,
               A.STARTWEIGHT,
               A.weightUinit,
               A.numberUinit,
               A.locationName,
               A.deptCode,
               SUM(B.inQuantity) AS inQuantity,
               SUM(B.inWieght) AS inWieght,
               SUM(B.outQuantity) AS outQuantity,
               SUM(B.outWieght) AS outWieght,
               SUM(B.lockQuantity) AS lockQuantity,
               SUM(B.lockWeight) AS lockWeight,
               SUM(B.stockTakingQuantity) AS stockTakingQuantity,
               SUM(B.stockTakingWeight) AS stockTakingWeight
          FROM STOCKQUANTITYITEM_VIEW A          LEFT  JOIN ALL_INFO_VIEW B ON A.id = B.id
           
         WHERE B.dateStr <= '2014-06-30'
and
           A.deptCode LIKE '001%'
           and A.warehouseID = 1428
         GROUP BY A.departmentName,
                  A.storeName,
                  A.companyName,
                  A.businessName,
                  A.stockType,
                  A.product,
                  A.manufactory,
                  A.material,
                  A.specString,
                  A.REFATTRIBUTES,
                  A.STARTNUMBER,
                  A.STARTWEIGHT,
                  A.id,
                  A.weightUinit,
                  A.numberUinit,
                  A.locationName,
                  A.deptCode) BB
如果红色部分放在上面的位置,如果左边有,右边没有,则不会保留左边的内容


分享到:
评论

相关推荐

    SQL语句left join/right join/inner join 的用法比较

    本篇文章将深入探讨LEFT JOIN、RIGHT JOIN以及INNER JOIN的用法,并通过实例进行对比,帮助理解它们之间的差异。 1. LEFT JOIN(左连接) LEFT JOIN返回所有左表(在本例中为A表)的记录,即使在右表(B表)中没有...

    inner join、 left join 、right join、 outer join之间的区别

    ### inner join、left join、right join、outer join之间的区别 在数据库操作中,连接(Join)是一种非常重要的操作,用于组合两个或多个表中的数据。根据连接的方式不同,可以分为几种类型:`INNER JOIN`、`LEFT ...

    hive sql + left join 数据缺失

    ### Hive SQL Left Join 数据缺失问题解析 #### 一、问题背景 在大数据处理场景中,Hive 是一种广泛使用的工具,用于对存储在 Hadoop 文件系统中的数据进行数据汇总、查询和分析。随着Hive版本的不断更新,部分用户...

    Left join优化规则的研究

    【Left Join 优化规则的研究】 在数据库查询优化中,Left Join 的处理是至关重要的,因为它涉及到数据的完整性和性能效率。对于应用开发人员而言,理解 Left Join 的优化规则能够提高查询效率,尤其是在某些数据库...

    sql的left join和count应用

    在SQL语言中,`LEFT JOIN` 和 `COUNT` 是两种非常重要的操作,它们在数据库查询中扮演着关键角色。在这个问题中,我们看到一个数据表 `TPL_WORD1`,它包含字段 `Wordid`(主键)、`idFuid`(上一级节点ID)和 `Name`...

    from 多张表 等于 left join 其他表.

    标题与描述中的“from多张表等于left join其他表”主要涉及的是SQL查询语句中两种不同的连接方式:内连接(通常在FROM子句后直接使用WHERE子句实现)和左连接(LEFT JOIN)。这两种连接方式在处理多表查询时有着不同...

    Linq to datable(Left join right join full join)实例

    Dim leftJoin = (From l In leftTable _ Join r In rightTable On l.Key Equals r.Key Into gj = Group _ From r In gj.DefaultIfEmpty() Select New With {l.Key, l.Value, r.Key, r.Value}) Dim rightJoin = ...

    SQL left join

    SQL Left Join SQLLeft Join是一种常用的数据库查询操作,它可以将两个或多个表格中的数据结合起来,以便更好地分析和处理数据。在本文中,我们将详细介绍SQL Left Join的使用方法、特点和区别,以及与Right Join...

    left join 过滤条件写在on后面和写在where 后面的区别

    ### left join 过滤条件写在on后面和写在where 后面的区别 在SQL查询语句中,连接(JOIN)是一种非常重要的操作,用于从两个或多个表中获取数据。其中,`LEFT JOIN`是一种常用的连接类型,它返回左表的所有记录以及...

    left join right join inner join 区别和联系

    左连接(LEFT JOIN)、右连接(RIGHT JOIN)和内连接(INNER JOIN)是三种最基本的连接类型。在本节中,我们将详细介绍左连接、右连接和内连接的区别和联系。 左连接(LEFT JOIN) 左连接返回左表中的所有行,右表...

    DataTable实现leftJoin和rightJoi以及innerJoin

    比较实用的方法,已经用到项目里,很好用的一个方法

    SQL语句inner join,left join ,right join连接的不同之处

    根据连接方式的不同,可以分为多种类型,包括内连接(Inner Join)、左连接(Left Join)以及右连接(Right Join)。本文将详细探讨这三种连接方式的区别,并通过具体的例子来解释它们的应用场景。 ### 内连接...

    (Left join , Right Join, Inner Join)用法详解

    ### (Left join , Right Join, Inner Join)用法详解 #### 一、基本概念与应用场景 在数据库查询语言SQL中,连接(Join)是一种非常重要的操作,它允许我们结合两个或多个表的数据来检索信息。根据不同的连接方式,...

    Sql语句用left join解决多表关联问题(关联套关联,例子和源码)

    Sql语句用left join解决多表关联问题(关联套关联,例子和源码)一看就明白多表关联如何写SQl语句

    关于sql的left join,right join,inner join,outerjoin

    本篇文章将深入探讨四种基本的JOIN类型:LEFT JOIN(左连接)、RIGHT JOIN(右连接)、INNER JOIN(内连接)以及OUTER JOIN(外连接)。我们将详细解释这些概念,它们的工作原理以及在实际数据库操作中的应用。 1. ...

    Mysql之innerjoin,leftjoin,rightjoin详解.pdf

    Mysql 之 inner join、left join、right join 详解 Mysql 中的连接查询是指从多个表中检索数据,并将它们组合成一个结果集。inner join、left join 和 right join 是 Mysql 中三种最常用的连接查询方式。 inner ...

    深入理解mysql之left join 使用详解

    关于 “A LEFT JOIN B ON 条件表达式” 的一点提醒 ON 条件(“A LEFT JOIN B ON 条件表达式”中的ON)用来决定如何从 B 表中检索数据行。 如果 B 表中没有任何一行数据匹配 ON 的条件,将会额外生成一行所有列为 ...

    Hive查询sql left join exists

    本文主要关注LEFT JOIN和EXISTS子句的使用,这两个都是数据查询中常见的技术,特别是在大数据处理领域,如Hadoop环境下的Hive。 首先,LEFT JOIN(左外连接)是连接两个表的一种方式,返回所有左表(在FROM子句中...

    SQL语句优化——in,not in,exists,not exists, left join...on博客所需SQL语句.txt

    SQL语句优化——in,not in,exists,not exists, left join...on博客所需SQL语句.txt欢迎下载!

Global site tag (gtag.js) - Google Analytics