表1:
document.addEventListener("DOMContentLoaded", function(){
var d = new Date(),
display = document.getElementById("dateDisplay");
display.innerHTML = d;
display.style.color = "red";
});
我需要一个查询来按ITEMS [ID, PRODUCT_ID, RUN_ID, NAME, LOCATION, LAST_MODIFIED]
和Product_ID
对所有项目进行分组。
像这样:
Run_ID
但是,我还需要Select Product_ID, Run_ID, Count(ID)
FROM ITEMS
Group by Product_ID, Run_ID
作为返回的每个组中的Location
(最新)项目。
所以从本质上讲,我需要获得一列的最大值,但为该行返回另一列。
答案 0 :(得分:1)
您可以使用window functions,// var commentId= "<?php echo $comment_id; ?>";
和ROW_NUMBER
实现此目的:
COUNT OVER
使用WITH Cte AS(
SELECT *,
cnt = COUNT(*) OVER(PARTITION BY Product_ID, Run_ID),
rn = ROW_NUMBER() OVER(PARTITION BY Product_ID, Run_ID ORDER BY last_modified DESC)
FROM ITEMS
)
SELECT
Product_ID, Run_ID, cnt, Location
FROM Cte
WHERE rn = 1
:
JOIN