我有一个返回一组记录的SQL语句:
SELECT
members.id,
members.name,
emlink.tank,
emlink.dps,
emlink.heal,
emlink.mid,
emlink.eid
FROM
members, emlink
WHERE members.id = $mid AND emlink.eid = $eid
结果:
1 Widget 0 0 1 1 8
1 Widget 1 0 0 1 8
如何将这些合并到单个记录中,如:
1 Widget 1 0 1 1 8
谢谢!
答案 0 :(得分:3)
你想要一个按位OR
吗?如果是这样,请使用MySQL的BIT_OR()
聚合函数:
SELECT members.id,
members.name,
BIT_OR(emlink.tank),
BIT_OR(emlink.dps ),
BIT_OR(emlink.heal),
BIT_OR(emlink.mid ),
BIT_OR(emlink.eid )
FROM members, emlink
WHERE members.id = $mid AND emlink.eid = $eid
在sqlfiddle上查看。
答案 1 :(得分:1)
SELECT M.id,
M.name,
MAX (E.tank),
MAX (E.dps),
MAX (E.heal),
MAX (E.mid),
E.eid
FROM members M,
emlink E
WHERE M.id = $mid
AND E.eid = $eid
GROUP BY M.id, M.name, E.eid
或者最符合您需求的聚合函数,SUM,MAX,BIT_OR等