SELECT u.USER_ID, u.USER_NAME, u.CHINESE_NAME, MENUS_NAME = stuff((SELECT “,” + m.MENUS_NAME FROM OC_CENTER_T_ASSOCIATION t, OC_CENTER_T_MENUS m WHERE t.MENUS_ID = m.MENUS_ID AND t.USER_ID = u.USER_ID FOR xml path (“”)),1,1,””) FROM OC_CENTER_T_USER u GROUP BY u.USER_ID, u.USER_NAME, u.CHINESE_NAME;
解决方案
40
SELECT TOP 10 * FROM (
SELECT row_number() OVER (ORDER BY USER_ID DESC) n, u.USER_ID, u.USER_NAME, u.CHINESE_NAME, MENUS_NAME = stuff((
SELECT “,” + m.MENUS_NAME FROM OC_CENTER_T_ASSOCIATION t, OC_CENTER_T_MENUS m
WHERE t.MENUS_ID = m.MENUS_ID AND t.USER_ID = u.USER_ID
FOR xml path (“”)),1,1,””) FROM OC_CENTER_T_USER u WHERE 1 = 1 GROUP BY u.USER_ID, u.USER_NAME, u.CHINESE_NAME ) w2 WHERE w2.n >10 AND w2.n<=20;
SELECT row_number() OVER (ORDER BY USER_ID DESC) n, u.USER_ID, u.USER_NAME, u.CHINESE_NAME, MENUS_NAME = stuff((
SELECT “,” + m.MENUS_NAME FROM OC_CENTER_T_ASSOCIATION t, OC_CENTER_T_MENUS m
WHERE t.MENUS_ID = m.MENUS_ID AND t.USER_ID = u.USER_ID
FOR xml path (“”)),1,1,””) FROM OC_CENTER_T_USER u WHERE 1 = 1 GROUP BY u.USER_ID, u.USER_NAME, u.CHINESE_NAME ) w2 WHERE w2.n >10 AND w2.n<=20;