• sql server 取多条数据的最大值


    实列:

     1 SELECT
     2  a.BillDate '[开票时间]',
     3  a.Hdbh '[运单号]',
     4  a.Status '运单状态',
     5  a.DisplayStatus '运单状态字',
     6  b.name '开票部门',
     7  d.name '运达部门',
     8  b.OrgAttributes '部门类型',
     9  e.MemberProblem,
    10  e.CustomerResponse,
    11  e.HandleSuggestion
    12 FROM
    13  shipment_bill a
    14  JOIN sys_organization b ON a.DepartmentId=b.id
    15  JOIN shipment_transport c ON a.id=c.BillId
    16  JOIN sys_organization d ON c.EndDepartment=d.id
    17  JOIN (SELECT g.BillId AS BillId ,g.MemberProblem AS MemberProblem ,g.CustomerResponse AS CustomerResponse,g.HandleSuggestion AS HandleSuggestion FROM member_tracking g JOIN (SELECT BillId,MAX(Id)AS Id FROM member_tracking GROUP BY BillId) f ON f.Id=g.Id) e ON e.BillId=a.id
    18 WHERE ---查询样表()
    19  Status IN ( 0, 1, 2, 3 ) 
    20  AND a.CreateTime < '2019-12-16' 
    21  AND a.IsValid = 1 
    22 ORDER BY
    23  a.BillDate
    ---
    SELECT
    g.BillId AS BillId ,g.MemberProblem AS MemberProblem ,g.CustomerResponse AS CustomerResponse,g.HandleSuggestion AS HandleSuggestion ---一层查询

    FROM member_tracking g

    JOIN
    (SELECT BillId,MAX(Id)AS Id FROM member_tracking GROUP BY BillId) f ON f.Id=g.Id---查询最大值(注意显示列只有两列,两列以上才疏学浅,还不会)
  • 相关阅读:
    java 之 对象与垃圾回收
    Java 之 内部类
    java 接口(interface)
    抽象类
    Java之fianl修饰符
    类的继承
    上传图片
    一般处理程序 给图片添加文字水印
    socket
    初识linq,lambda表达式
  • 原文地址:https://www.cnblogs.com/superduan/p/12102796.html
Copyright © 2020-2023  润新知