我想根据我的隐私设置列出文件夹和文件。向创建者显示它时,它没有看到其他指定的用户,没有任何问题。仅列出公用文件夹。
角色:
1:自定义
2:特定用户
3:专用滚筒
4:公开/所有人开放
按创建者查询:
SELECT
f.file_id, f.is_folder, f.file_name, f.name as folder_name, f.created_at, f.privacy, f.users, f.roles, (SELECT name FROM users WHERE id = f.created_by) AS name, (SELECT surname FROM users WHERE id = f.created_by) AS surname
FROM files AS f
WHERE
CASE
WHEN f.privacy = 2 THEN ((f.users IS NOT NULL AND FIND_IN_SET(1, f.users)) OR f.created_by = 1)
WHEN f.privacy = 3 THEN ((f.roles IS NOT NULL AND FIND_IN_SET(1, f.roles)) OR f.created_by = 1)
WHEN f.privacy = 4 THEN (f.created_by = 1 OR f.created_by <> 1)
ELSE f.created_by = 1
END
AND f.folder_id = 0
ORDER BY f.name ASC LIMIT 0, 25
http://sqlfiddle.com/#!9/bae05e/5/0
受让人查询:
SELECT
f.file_id, f.is_folder, f.file_name, f.name as folder_name, f.created_at, f.privacy, f.users, f.roles, (SELECT name FROM users WHERE id = f.created_by) AS name, (SELECT surname FROM users WHERE id = f.created_by) AS surname
FROM files AS f
WHERE
CASE
WHEN f.privacy = 2 THEN ((f.users IS NOT NULL AND FIND_IN_SET(10, f.users)) OR f.created_by = 10)
WHEN f.privacy = 3 THEN ((f.roles IS NOT NULL AND FIND_IN_SET(2, f.roles)) OR f.created_by = 10)
WHEN f.privacy = 4 THEN (f.created_by = 10 OR f.created_by <> 10)
ELSE f.created_by = 10
END
AND f.folder_id = 0
ORDER BY f.name ASC LIMIT 0, 25
答案 0 :(得分:0)
我对查询做了一些修正
希望这会有所帮助
SELECT
f.file_id, f.is_folder, f.file_name, f.name as folder_name, f.created_at, f.privacy, f.users, f.roles
, u.name, u.surname
FROM
files AS f
LEFT JOIN users u ON u.id = f.created_by
WHERE
(
(f.privacy = 2 AND LOCATE(IFNULL(f.roles,''),10))
OR
(f.privacy = 3 AND LOCATE(IFNULL(f.roles,''),2))
OR
f.privacy = 4
)
AND f.folder_id = 0
;