答案 0 :(得分:1)
查看类似的内容(我没有你的桌子,但你会知道在哪里查看你的查询):
SELECT DirectName,
MAX(UpdatedDate),
MAX(LastPublished),
(
SELECT COUNT(*)
FROM PublishedData inr
WHERE inr.DirectName = outr.DirectName
AND inr.IsPublished = 0
) AS Unpublished
FROM PublishedData outr
GROUP BY DirectName
答案 1 :(得分:1)
我认为你可以使用这样的查询:
SELECT dt.DistrictName, ISNULL(dt.Content, 'N/A') Content, dt.UpdatedDate, mt.LastPublished, mt.Unpublished
FROM (
SELECT *, ROW_NUMBER() OVER (PARTITION BY DistrictName ORDER BY UpdatedDate DESC, ISNULL(Content, 'zzzzz')) seq
FROM PublishedData) dt
INNER JOIN (
SELECT DistrictName, MAX(LastPublished) LastPublished, COUNT(CASE WHEN IsPublished = 0 THEN 1 END) Unpublished
FROM PublishedData
GROUP BY DistrictName) mt
ON dt.DistrictName = mt.DistrictName
WHERE
dt.seq = 1;
因为我认为你使用超过UpdatedDate, Content
的订单来获得两个第一列。
答案 2 :(得分:0)
我们应该在PublishedData表中要求输出所需的唯一标识,因为我们无法从给定的模式中获取最新内容。
的 如果您希望数据与DistictName,updatedDate,LastPublishedDate和未发布记录的数量不同,请使用下面的查询:
i.send("#{v}=", chunks[k])