我不知道该怎么做……
表'child':
idchild | name | idability
--------------------------
1 | Joe | 1
1 | Joe | 2
2 | Peter| 1
2 | Peter| 3
3 | Kate | 4表‘能力’:
idability | ability
-------------------
1 | run
2 | read
3 | write
4 | swim例如,Joe可以“跑”和“读”,但不能“写”或“游”。我需要一份关于乔能力的清单:
ability |
-----------------
run | +
read | +
write | -
swim | -我以不同的方式尝试了几个SQL查询(使用“NOT EXIST”),但从未得到正确的结果。我希望有人能告诉我该怎么做。
提前谢谢你!
发布于 2012-12-31 03:47:07
这应该没问题:
select ability.ability, if(child.idability,'+','-') from ability left join child on ability.idability =child.idability and child.name="joe";发布于 2012-12-31 03:21:54
试试这个:
select `child`.`idChild`,`child`.`name`, `child`.`idability`, `ability`.`idAbility`,`ability`.`ability` from `child` inner join `ability` on `child`.`idAbility` = `ability`.`idability` order by `child`.`name`, `ability`.`ability`您可以删除不需要的列。
https://stackoverflow.com/questions/14093795
复制相似问题