日期:2014-05-18  浏览次数:20542 次

求个函数的sql语句~~万分感谢!!
SQL code

SELECT u.VIDEO_ID
         FROM   T_USER_LEARNING_RECORD AS u ,
                dbo.T_VIDEO AS v
         WHERE  u.VIDEO_ID = v.VIDEO_ID
                AND u.LEARNING_TIME >= v.TIME_LENGTH
                AND u.USER_ID = @user_id
                
         SELECT VIDEO_ID FROM dbo.T_VIDEO WHERE COURSE_ID=@course_id


上面两个sql语句都是找VIDEO_ID的,怎么在数据库中写一个函数判断一个查找到的集合是不是在另一个查找的集合里面,怎么去实现?函数两个参数@user_id、 @course_id


------解决方案--------------------
SQL code

SELECT CASE COUNT(1) WHEN 0 THEN 'true'
        ELSE 'false' END AS Ifcontain
FROM   T_USER_LEARNING_RECORD AS u ,
       dbo.T_VIDEO AS v
WHERE  u.VIDEO_ID = v.VIDEO_ID
       AND u.LEARNING_TIME >= v.TIME_LENGTH
       AND u.USER_ID = @user_id AND EXISTS (SELECT 1 FROM dbo.T_VIDEO AS A WHERE COURSE_ID=@course_id AND A.VIDEO_ID <> v.VIDEO_ID)