批次导数据表头

SELECT [运单号] ,
[运单号] AS [订单号] ,
[运单号] AS [订单号] ,
[运单号] ,
SUM([price] * [ProductNum]) AS [订单总价] ,
SUM(CAST(( temp.[Weight] * ( CAST (temp.ProductNum AS DECIMAL(18, 2))
/ temp.ProductSumNum ) ) AS NUMERIC(18, 2))) AS [毛重] ,
SUM(CAST(( temp.[Weight] * ( CAST (temp.ProductNum AS DECIMAL(18, 2))
/ temp.ProductSumNum ) ) AS NUMERIC(18, 2))
- 0.01) AS [净重] ,
temp2.TrueName AS [收货人] ,
temp2.Adrress AS [收货人地址] ,
CASE temp2.Mobile
WHEN '' THEN temp2.Phone
ELSE temp2.Mobile
END AS [电话] ,
temp.币制 ,
'' AS [orderType] ,
'' AS [trafMode] ,
'' AS [portCode] ,
'' AS [licenseNo] ,
'' AS [wrapType] ,
'' AS [freight] ,
'' AS [insuredFee] ,
'' AS [freightMark] ,
'' AS [insuredFeeMark] ,
'' AS [goodsInfo] ,
'' AS [consigneeCountry] ,
'' AS [shipper] ,
'' AS [shipperAddress] ,
'' AS [shipperTelephone] ,
'' AS [shipperCountry] ,
'' AS [orderNote] ,
'' AS [logisticsNote] ,
'' AS [InventoryNote] ,
'' AS [trafName] ,
'' AS [voyageNo] ,
'' AS [billNo] ,
'1' AS packNo
FROM ( SELECT a.TransportOrderCode AS [运单号] ,
MAX(ISNULL(d.CatalogName,
SUBSTRING(ProductCatalogName,
CHARINDEX('-', ProductCatalogName)
+ 1, LEN(ProductCatalogName)))) CatalogName ,
d.itemName ,
d.itemNo ,
d.gcode AS Hscode ,
CASE WHEN a.Weight < 0.02 THEN 0.02
ELSE a.Weight
END AS [Weight] ,
SUM(c.ProductNum) AS ProductNum ,
CAST(CAST(SUM(c.TotalItemActualPrice) * 0.1498 AS DECIMAL(11,
2))
/ SUM(c.ProductNum) AS DECIMAL(11, 2)) [price] ,
'美元' AS [币制] ,
dbo.Fun_GetTransportProductNum(a.TransportOrderID) AS ProductSumNum ,
d.unit ,
d.unit1
FROM dbo.TWX_TransportOrder a WITH ( NOLOCK )
LEFT JOIN dbo.TWX_TransportFromMst b WITH ( NOLOCK ) ON a.TransportOrderID = b.TransportOrderID
LEFT JOIN dbo.TWX_TransportFromDtl c WITH ( NOLOCK ) ON b.TransportFormMstID = c.TransportFormMstID
LEFT JOIN dbo.TBD_ProductCatalog_MAP_KJT d WITH ( NOLOCK ) ON c.ProductCatalogID = d.CatalogID
AND c.DeleteUser = 0
WHERE a.StatusFlag >= 20
AND a.LogisticsTransferDtlID IN (
SELECT LogisticsTransferDtlID
FROM dbo.TWX_LogisticsTransferDtl WITH ( NOLOCK )
WHERE LogisticsTransferDtlCode IN (
SELECT [LogisticsTransferDtlCode]
FROM TWX_ScanLogisticsTransfer WITH ( NOLOCK )
WHERE DeleteUser = 0
AND BatchNo = '113020170828' ) )
GROUP BY a.TransportOrderCode ,
itemName ,
itemNo ,
d.gcode ,
a.Weight ,
d.unit ,
a.TransportOrderID ,
d.unit1
) temp
LEFT JOIN dbo.TWX_TransportOrder temp2 ON temp.[运单号] = temp2.TransportOrderCode
GROUP BY temp.[运单号] ,
temp.[币制] ,
temp2.TrueName ,
temp2.Adrress ,
temp2.Mobile ,
temp2.Phone;

-------------------------------------------------------------------.

(SELECT TOP 1 C.CreateTime FROM TWX_LogisticsTransferDtl A
LEFT JOIN TWX_ScanLogisticsTransfer C ON A.LogisticsTransferDtlCode=C.LogisticsTransferDtlCode
WHERE A.LogisticsTransferDtlID=a.LogisticsTransferDtlID
) AS '装车时间',
(
SELECT TOP 1 N.TrackTime FROM
[dbo].[Log_TransportOrderTrack] N WHERE N.TransportOrderCode=a.TransportOrderCode AND N.TrackCode IN ('CAI_CUSTOMS_CLR_SUC_00','CAI_CUSTOMS_CLR_SUC_HK')
) AS '到港时间',
(
SELECT TOP 1 N.TrackTime FROM
[dbo].[Log_TransportOrderTrack] N WHERE N.TransportOrderCode=a.TransportOrderCode AND N.TrackCode='CAI_SIGN_IN'
)
AS '签收时间'

比较好的SQL语句的更多相关文章

  1. mysql学习之 sql语句的技巧及优化

    一.sql中使用正则表达式 select name,email from user where email Regexp "@163[.,]com$"; sql语句中使用Regex ...

  2. 一条Sql语句分组排序并且限制显示的数据条数

    如果我想得到这样一个结果集:分组排序,并且每组限定记录集的数量,用一条SQL语句能办到吗? 比如说,我想找出学生期末考试中,每科的前3名,并按成绩排序,只用一条SQL语句,该怎么写? 表[TScore ...

  3. LINQ to SQL语句(7)之Exists/In/Any/All/Contains

    适用场景:用于判断集合中元素,进一步缩小范围. Any 说明:用于判断集合中是否有元素满足某一条件:不延迟.(若条件为空,则集合只要不为空就返回True,否则为False).有2种形式,分别为简单形式 ...

  4. Oracle ------ SQLDeveloper中SQL语句格式化快捷键

    Oracle SQL Developer中SQL语句格式化快捷键: 每次sql复制到SQL Developer面板的时候,格式老不对,而且看起来很不舒服,所有的sql都挤在一行完成. 这时我们可以全选 ...

  5. SQL语句优化

    (1)      选择最有效率的表名顺序 ( 只在基于规则的优化器中有效 ) : ORACLE 的解析器按照从右到左的顺序处理 FROM 子句中的表名, FROM 子句中写在最后的表 ( 基础表dri ...

  6. LinqToDB 源码分析——生成与执行SQL语句

    生成SQL语句的功能可以算是LinqToDB框架的最后一步.从上一章中我们可以知道处理完表达式树之后,相关生成SQL信息会被保存在一个叫SelectQuery类的实例.有了这个实例我们就可以生成对应的 ...

  7. 年终巨献 史上最全 ——LINQ to SQL语句

    LINQ to SQL语句(1)之Where 适用场景:实现过滤,查询等功能. 说明:与SQL命令中的Where作用相似,都是起到范围限定也就是过滤作用的,而判断条件就是它后面所接的子句.Where操 ...

  8. LINQ to SQL语句(19)之ADO.NET与LINQ to SQL

    它基于由 ADO.NET 提供程序模型提供的服务.因此,我们可以将 LINQ to SQL 代码与现有的 ADO.Net 应用程序混合在一起,将当前 ADO.NET 解决方案迁移到 LINQ to S ...

  9. LINQ to SQL语句(17)之对象加载

    对象加载 延迟加载 在查询某对象时,实际上你只查询该对象.不会同时自动获取这个对象.这就是延迟加载. 例如,您可能需要查看客户数据和订单数据.你最初不一定需要检索与每个客户有关的所有订单数据.其优点是 ...

  10. LINQ to SQL语句(6)之Group By/Having

    适用场景:分组数据,为我们查找数据缩小范围. 说明:分配并返回对传入参数进行分组操作后的可枚举对象.分组:延迟 1.简单形式: var q = from p in db.Products group ...

随机推荐

  1. Docker的初体验

    这几天捣鼓了一下docker,是真的麻烦啊,网上资料比较杂乱,也很多英文,学起来挺多问题的 Docker下载 win10专业版:开启Hyper-V,下载并安装 docker-for-windows(但 ...

  2. java获取地址全路径

      String basePath = request.getScheme()+"://"+request.getServerName()+":"+reques ...

  3. :nohlsearch

    vim 编辑器 ——黄色阴影的消除问题 - leikun153的博客 - CSDN博客 https://blog.csdn.net/leikun153/article/details/78903597 ...

  4. 转!!Java虚拟机堆的内存分配和回收

    Java内存分配和回收,主要就是指java堆的内存分配和回收.java堆一般分为2个大的区域,一块是新生代,一块是老年代.在新生代中又划分了3块区域,一块eden区域,两块surviver区域.一般称 ...

  5. 关于Nginx部署Django项目的资料收集

    参考:https://www.cnblogs.com/chenice/p/6921727.html 参考:https://blog.csdn.net/fengzq15/article/details/ ...

  6. requests 中response如何改变编码格式

    查看初始编码 首先查看拿到的response编码格式: (就不放代码了,因为此例需要用到cookie,可自行找个网站具体测试) 可见初始编码为:ISO-8859-1 修改编码 初始编码: 修改后编码: ...

  7. OVN实战---《An Introduction to OVN Routing》翻译

    Overview 在前面一篇文章的基础上,现在我将通过OVN创建一个基础的三层网络.创建的最终结果将是一对logical switches通过一个logical router相连.另外,该路由器会通过 ...

  8. mui请求数据

    var rh = new Object(); rh.ReqId = "ls123"; rh.Salt = "sssseee"; var rb = new Obj ...

  9. 001-es6变量声明、解构赋值、解构赋值主要用途

    一.基本语法 1.1.声明变量的六种方法 参看地址:http://es6.ruanyifeng.com/#docs/let let:局部变量,块级作用域,声明前使用报错 var:全局变量,声明前使用 ...

  10. Python和数据科学的起步指南

    http://python.jobbole.com/80853/ Python拥有着极其丰富且稳定的数据科学工具环境.遗憾的是,对不了解的人来说这个环境犹如丛林一般(cue snake joke).在 ...