用户表 table_1id name sex status1 渣渣徽 1 1 2 谷田乐 1 1用户角色等级表 table_2UID 为表一关联字段
id uid level_name level_id1 1 青铜 1 1 1 白银 21 2 白银 21 2 黄金 3查询所有青铜等级的用户,这样单条件没问题SQLselect * from table_1 RIGHT JOIN table_2 ON table_1.id = table_2.uidwhere table_1.status = 1 AND table_2.level_id = 1 group by table_1.id但是如何查询同时拥有青铜与白银的角色呢?如下查询条件是不行的select * from table_1 RIGHT JOIN table_2 ON table_1.id = table_2.uidwhere table_1.status = 1 AND table_2.level_id = 1 AND table_2.level_id = 2此条件该如何查询?
2 回答
翻翻过去那场雪
TA贡献2065条经验 获得超13个赞
SELECT LEFT(Group_concat(level_id), Length('1,2')) AS gid, uid, `name`FROM table_1 AS a LEFT JOIN table_2 AS b ON a.id = b.uidGROUP BY uidHAVING gid = '1,2'
添加回答
举报
0/150
提交
取消