批次导数据表头

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. 3年工作经验的Java程序员面试经

    转发自用~ 一.Java基础部分 1.使用length属性获取数组长度,public.private.protected.friendly区别 2.Collection和Collections区别 3 ...

  2. FineReport---过滤条件

    1.过滤条件,获取值 该单元格的值 ,是当team为A,content为产量 数据列过滤条件常用处理:nofilter.left.and ,or 2.单元格值等查询条件区域的内容 所选你应该指的就是日 ...

  3. Powershell About File System

    File System Rights Get-Acl $sharepath | select -expand access | where { !$_.IsInherited -AND $_.file ...

  4. Ad Exchange

    品友互动-基于大数据技术的人工智能决策平台 http://www.ipinyou.com.cn/about?flag=milestones

  5. divison in python2 and python3

    python2 >>> / >>> /2.0 1.5 >>> / >>> /2.0 2.0 >>> >& ...

  6. Pandas 横向合并DataFrame数据

    需要将两个DataFrame进行横向拼接: 对 A_DataFrame 拼接一列数据: 数据样例如下: 将右侧source_df中的 “$factor” 列拼接到左侧qlib_df中,但左侧数据是分钟 ...

  7. Andrew Ng机器学习编程作业:Neural Network Learning

    作业文件: machine-learning-ex4 1. 神经网络 在之前的练习中,我们已经实现了神经网络的前反馈传播算法,并且使用这个算法通过作业给的参数值预测了手写体数字.这个练习中,我们将实现 ...

  8. python库numpy的reshape的终极解释

    a = np.arange(2*4*4) b = a.reshape(1,4,4,2)           #应该这样按反序来理解:最后一个2是一个只有2个元素的向量,最后的4,2代表4×2的矩阵,最 ...

  9. Web框架(Day64)

    阅读目录 http协议 web应用与web框架 一.http协议 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World W ...

  10. go——函数

    1.定义 函数是结构化编程的最小单元模式.它将复杂的算法过程分解为若干个较小任务,隐藏相关细节,使程序结构更加清晰,易于维护.函数被设计成相对独立,通过接收输入参数完成一段算法指令,输出或存储相关结果 ...