Document

Union all的用法实例sql

---Union all的用法实例sql
SELECT TOP (100) PERCENT ID, bid_user_id, UserName, amount, createtime, borrowType
FROM (SELECT bid.ID, bid.bid_user_id, reg.UserName, bid.amount, bid.createtime, '普通标' AS borrowType
FROM dbo.YYD_Borrow_BidRecord AS bid
INNER JOIN dbo.YYD_Users_RegInfo AS reg ON reg.ID = bid.bid_user_id
WHERE (bid.ID NOT IN(SELECT bid
FROM dbo.HUR_NewPlanLoan_ItemLoan)) AND (bid.ID NOT IN
(SELECT bidID FROM dbo.HUR_Product_Matching))

UNION ALL

SELECT bid.id, bid.userid, reg.UserName, bid.amount, bid.createtime, '计划' AS borrowType
FROM dbo.HUR_NewPlanLoan_BidRecord AS bid
INNER JOIN dbo.YYD_Users_RegInfo AS reg ON reg.ID = bid.userid

UNION ALL

SELECT buy.buyID, buy.userID, reg.UserName, buy.amount, buy.createDate, '随心买' AS borrowType
FROM dbo.HUR_Product_Buy AS buy
INNER JOIN dbo.YYD_Users_RegInfo AS reg ON reg.ID = buy.userID) AS data
ORDER BY bid_user_id, createtime DESC

posted @ 2016-07-25 15:32  从未被超越  阅读(1112)  评论(0编辑  收藏  举报