mysql中如何按条件去重
如有一个表textidnameGRADE1zs252ls263wqnull4kjnull5lk25我只想把GRADE列的非null字段去重得到效果为idnameGRADE...
如有一个表text
id name GRADE
1 zs 25
2 ls 26
3 wq null
4 kj null
5 lk 25
我只想把GRADE列的非null字段去重
得到效果为
id name GRADE
1 zs 25
2 ls 26
3 wq null
4 kj null 展开
id name GRADE
1 zs 25
2 ls 26
3 wq null
4 kj null
5 lk 25
我只想把GRADE列的非null字段去重
得到效果为
id name GRADE
1 zs 25
2 ls 26
3 wq null
4 kj null 展开
3个回答
推荐于2018-04-05 · 知道合伙人数码行家
关注
展开全部
利用group by
代码如下:
SELECT * FROM(
select * from customer where user=(
SELECT source_user from customer WHERE user='admin') UNION ALL select * from customer where user=(
select source_user from customer where user=(
SELECT source_user from customer WHERE user='admin')) union ALL select * from customer where user=(
select source_user from customer where user=(
select source_user from customer where user=(
SELECT source_user from customer WHERE user='admin'))) UNION ALL select * from customer where source_user=(/*我的上线的上线的user*/
select user from customer where user=(
select source_user from customer where user=(
SELECT source_user from customer WHERE user='admin'))) union all select * from customer where source_user=(/*我的上线的上线的上线user*/
select user from customer where user=(
select source_user from customer where user=(
select source_user from customer where user=(
SELECT source_user from customer WHERE user='admin'))))) as alias group by user;
代码如下:
SELECT * FROM(
select * from customer where user=(
SELECT source_user from customer WHERE user='admin') UNION ALL select * from customer where user=(
select source_user from customer where user=(
SELECT source_user from customer WHERE user='admin')) union ALL select * from customer where user=(
select source_user from customer where user=(
select source_user from customer where user=(
SELECT source_user from customer WHERE user='admin'))) UNION ALL select * from customer where source_user=(/*我的上线的上线的user*/
select user from customer where user=(
select source_user from customer where user=(
SELECT source_user from customer WHERE user='admin'))) union all select * from customer where source_user=(/*我的上线的上线的上线user*/
select user from customer where user=(
select source_user from customer where user=(
select source_user from customer where user=(
SELECT source_user from customer WHERE user='admin'))))) as alias group by user;
2012-12-25
展开全部
直接查出来,通过数组循环,非空的以GRADE为key值,进行重铸数组就可以了。不需要去复杂的查库。
来自:求助得到的回答
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
考虑使用union连接两种情况的数据,给个示例:
select id, name, grade from `text` where grade is not null group by grade
union all
select id, name, grade from `text` where grade is null
select id, name, grade from `text` where grade is not null group by grade
union all
select id, name, grade from `text` where grade is null
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |