我有这个sql:
SELECT
m.member_id,
m.login,
p.type
FROM
permissions p
INNER JOIN members m ON p.member_id = m.member_id
WHERE
K_id = '$kid'
ORDER BY p.type DESC
我想要做的是,如果p.type = 2包裹在div id = 2中,并且如果p.type = 1包裹在div id = 1中。如何在连接操作后完成?
答案 0 :(得分:1)
我相信你是在CASE声明之后
SELECT
m.member_id,
m.login,
p.type,
CASE p.type
WHEN 1 THEN '<div id=1>'
WHEN 2 THEN '<div id=2>'
END as MyDiv
FROM
permissions p
INNER JOIN members m ON p.member_id = m.member_id
WHERE
K_id = '$kid'
ORDER BY p.type DESC