看板 Database 關於我們 聯絡資訊
這樣會比較簡單嗎? select type ,substring(mintext,0,charindex('@',mintext)) as date ,substring(mintext,charindex('@',mintext)+1,50) as ext ,sumamt from ( select type,min(date+'@'+ext) as mintext,sum(amt) as sumamt from table group by type ) a ※ 引述《SangoGO (隱世的外來人Lv.1)》之銘言: : 資料庫名稱:MS SQL : 資料庫版本:2012 : 內容/問題描述: : 各位先進好 : 自己在公司專案的開發上碰到了查詢上的難題 : 如下圖範例所示 : http://i.imgur.com/mL6ulEi.png
: 左邊是原始Insert的資料 : 中間是依照TYPE與DATE排序的結果 : 右邊為預期產出 : 用Group by能直接算出各TYPE的AMT和 : 但旁邊的DATE與VALUE就缺乏有效的取得方法 : 有試過用子查詢去抓 : 但因為實際筆數過大(可能有100,000)而速度緩慢 : 又或者讓結果去找原表,每筆0.1秒的話,6000筆就要10分鐘了 : 是否有更好解決的方法呢,求各位先進開示了 : ----- : Sent from JPTT on my Sony E6853. -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 182.234.36.193 ※ 文章網址: https://www.ptt.cc/bbs/Database/M.1502203729.A.0A3.html