Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 添加一列的值_Sql_Sql Server 2008 - Fatal编程技术网

Sql 添加一列的值

Sql 添加一列的值,sql,sql-server-2008,Sql,Sql Server 2008,我试图通过基于键值添加一列的值来获取记录。以下是我的疑问: SELECT PM_ProductPayment.ProjectId, SalesDetail.SalesPerson, PM_ProductCost.ProductCost, dbo.PM_ProductPayment.ProductPayment, dbo.PM_ProductPayment.PaymentDate FROM dbo.PM_ProductPayment IN

我试图通过基于键值添加一列的值来获取记录。以下是我的疑问:

SELECT    
    PM_ProductPayment.ProjectId, SalesDetail.SalesPerson,
    PM_ProductCost.ProductCost, dbo.PM_ProductPayment.ProductPayment, 
    dbo.PM_ProductPayment.PaymentDate    
FROM    
    dbo.PM_ProductPayment 
INNER JOIN 
    dbo.PM_Product ON dbo.PM_ProductPayment.ProjectId = dbo.PM_Product.ProductId    
INNER JOIN 
    dbo.PM_ProductCost ON dbo.PM_ProductPayment.ProductId = dbo.PM_ProductCost.ProductId    
INNER JOIN 
    dbo.SalesDetail ON dbo.PM_Product.SalesPersonId = dbo.SalesDetail.ID 
我得到的结果是:

现在,我想通过为每个产品和最后一个付款日期添加“付款”来获得单行

请优化我的查询或建议其他更好的方法


谢谢,

您想要的结果是什么?请不要发布图片,而是我们可以复制/粘贴的代码。您可以使用
{}
-按钮在编辑器中格式化代码。谢谢juergen d。但如果我必须为“付款备注”添加一列,该怎么办?
SELECT pay.ProjectId, 
       sum(pay.ProductPayment),
       max(pay.PaymentDate) 
FROM dbo.PM_ProductPayment pay
INNER JOIN dbo.PM_Product pro ON pay.ProjectId = pro.ProductId    
INNER JOIN dbo.PM_ProductCost cos ON pay.ProductId =cos.ProductId    
INNER JOIN dbo.SalesDetail sal ON pro.SalesPersonId = sal.ID 
GROUP BY pay.ProjectId