码迷,mamicode.com
首页 > 数据库 > 详细

Union all的用法实例sql

时间:2016-07-25 15:52:16      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:

---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

Union all的用法实例sql

标签:

原文地址:http://www.cnblogs.com/zxtceq/p/5703704.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!