檔案狀態:    住戶編號:2634222
 Lake 的日記本
快速選單
到我的日記本
看他的最新日記
加入我的收藏
瀏覽我的收藏
ㄚ~~ 《前一篇 回他的日記本 後一篇》 知足
 切換閱讀模式  回應  給他日記貼紙   給他愛的鼓勵  檢舉
篇名: 專業阿...
作者: Lake 日期: 2013.07.04  天氣:  心情:
SELECT a.office
, max(lastdate) AS DeptLastDate
, datediff(DAY, convert(VARCHAR(10), max(lastdate), 111), getdate()) AS DiffDay
, l.Description
FROM
(SELECT d.Department
, left(d.Department, 2) + 00 AS office
, convert(VARCHAR(10), max(StartDate), 111) AS lastdate
FROM
DisasterCount AS D
JOIN LunchBox.dbo.location AS l
ON d.Department = l.DepCode
WHERE
Enabled = 1
AND hurt LIKE %x能%
AND d.Department NOT LIKE U3%
GROUP BY
d.Department) AS a
JOIN LunchBox.dbo.location AS l
ON a.office = l.DepCode
GROUP BY
a.office
, l.Description UNION
SELECT a.office
, max(lastdate) AS DeptLastDate
, datediff(DAY, convert(VARCHAR(10), max(lastdate), 111), getdate()) AS DiffDay
, xx AS DESCRIPTION
FROM
(SELECT TOP 1 Department
, left(Department, 3) + 0 AS office
, convert(VARCHAR(10), max(StartDate), 111) AS lastdate
FROM
DisasterCount
WHERE
Enabled = 1
AND hurt LIKE %x能%
AND Department LIKE U3%
AND Department < U380
GROUP BY
Department order by lastdate desc) as a
group by a.office union SELECT a.office
, max(lastdate) AS DeptLastDate
, datediff(DAY, convert(VARCHAR(10), max(lastdate), 111), getdate()) AS DiffDay
, oo AS DESCRIPTION
FROM
(SELECT TOP 1 Department
, left(Department, 3) + 0 AS office
, convert(VARCHAR(10), max(StartDate), 111) AS lastdate
FROM
DisasterCount
WHERE
Enabled = 1
AND hurt LIKE %x能%
AND Department LIKE U3%
AND Department >= U380
GROUP BY
Department order by lastdate desc) as a
group by a.office
標籤:
瀏覽次數:24    人氣指數:24    累積鼓勵:0
 切換閱讀模式  回應  給他日記貼紙   給他愛的鼓勵 檢舉
給本文愛的鼓勵:  最新愛的鼓勵
ㄚ~~ 《前一篇 回他的日記本 後一篇》 知足
 
給我們一個讚!