我们如何在这种情况下使用联盟 [英] How we can use union on this situation

查看:76
本文介绍了我们如何在这种情况下使用联盟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

My Table like this

id  name col1
1   a    2
2   b    1
3   c    1
4   d    0
5   e    0
6   f    3
7   g    3

And i want output like this where 
1st i want my list in ASC oreder except "0"
and at the end i want to merge the all row that contains "0"

name col1
b    1
c    1
a    2
f    3
g    3
d    0
e    0

推荐答案

首先将其视为两个查询



think of it as two queries first

select name, col1 from table where col1 != 0 order by name








and

select name, col1 from table where col1 = 0 order by name





现在,如果你想到我的'和'作为'联盟',你应该知道如何把这两个问题放在一起(你可能需要稍微修改我的SQL,我不确定是否例如!=在你的SQL平台中有效,但你应该明白这个想法)



给它一个机会,玩耍 - 你学习的唯一方法是通过做,也许做错了,但再尝试



now, if you think of my 'and' as a 'union' you should know what to do to put the two queries together (you may need to modify my SQL slightly, Im not sure if for example != is valid in your SQL platform, but you should get the idea)

give it a shot, play around - the only way you learn is by doing, maybe getting it wrong, but then trying again


这篇关于我们如何在这种情况下使用联盟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆