如何获得两个日期之间的值之和

时间:2016-11-23 06:00:04

标签: sql sql-server

我的查询是

select 
    ir.ProductId,
    sum(ir.IssueQuantity) as 'Quantity',
    p.ProductName,
    ir.IssueDate,
    ir.ReturnDate
from Product.IssueReturn ir 
join Company.Product p on p.ProductId=ir.ProductId
group by ir.ProductId,p.ProductName,ir.IssueDate,ir.ReturnDate

2 个答案:

答案 0 :(得分:0)

删除选择中的日期字段列。

var data = [
  {
    "id": 10000,
    "transactionid": "gec43434",
    "status": "COMPLETED",
    "session_id": "TTYUU455667",
    "errors": "1",
    "start_timestamp": "2016-11-07 02:35:35",
    "log_field": "Sample Text For Testing"
  },
  {
    "id": 10001,
    "transactionid": "r34fdfdf",
    "status": "COMPLETED",
    "session_id": "dfdfer3453df",
    "errors": "3",
    "start_timestamp": "2016-10-07 03:20:15",
    "log_field": "Sample Text2 For Testing"
  }
];

var newData = [];

data.forEach(function(object) {

  // Create a new temporary object
  var temp = {
    subItems: {}
  };

  // Loop through the existing object
  for (var key in object) {

    // Leave the log field out of sub items
    if (key === "log_field") temp[key] = object[key];

    // Add all other keys/values to the subItems object
    temp["subItems"][key] = object[key];
  }

  // Push the new object to the newData array
  newData.push(temp);
});

console.log(newData);

答案 1 :(得分:0)

SELECT 
    ProductId ,  PrdName , 
    SUM(IssueQuantity) IssueQuantity ,
    MIN(IssueDate) IssueDate,MAX(ReturnDATE) ReturnDATE 
FROM Table1 join Table2 on ProductId = ProductId 
GROUP BY ProductId , PrdName