目前日期文章:201111 (2)

瀏覽方式: 標題列表 簡短摘要

●合併重覆行
select * from A
union
select * from B


●不合併重覆行
select * from A
union all
select * from B


●按某個欄位排序--合併重覆行
select * from
(select * from A
union
select * from B) AS T
order by 欄位名

●按某個欄位排序--不合併重覆行
select * from
(select * from A
union all
select * from B) AS T
order by 欄位名

●GROUP BY 用法一樣

EX:

SELECT CCY, SUM(AMOUNT) FROM (
(SELECT  'CCY' = CURBUY, 'AMOUNT' = SUM(AMTBUY) FROM vw_CCYAMT  GROUP BY CURBUY)
UNION ALL
(SELECT  'CCY' = CURSEL, 'AMOUNT' = (SUM(AMTSEL) * -1) FROM vw_CCYAMT  GROUP BY CURSEL)
) AS T GROUP BY CCY


egalemouse 發表在 痞客邦 留言(0) 人氣()

1.在T-SQL裡IF的開頭與結尾要用BEGIN跟END。
EX:

IF A = B
BEGIN
    ........
    ........
    ........
END
ELSE IF B = C
BEGIN
    ........
    ........
END


2.在T-SQL裡TABLE名稱不能用變數

ps: T-SQL就是純量變數(我自己定義的~哈哈哈~XD)


egalemouse 發表在 痞客邦 留言(0) 人氣()