-1

我有一个返回一组记录的 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 

谢谢!

4

2 回答 2

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上查看。

于 2012-11-15T19:01:10.853 回答
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 等

于 2012-11-15T19:02:46.873 回答