我们如何在这种情况下使用联盟
问题描述:
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