微信 卖性保健品 案例:求一条关于union 的SQL语句~

来源:百度文库 编辑:高考问答 时间:2024/04/29 07:55:21
不知道举什么例子好,就拿baidu来说吧,

如果我给钱百度做推广,在有效时间内,经过审核,可以排在搜索最前面,其他比我给的钱少的网站排在我网站后面,没有给钱的客户根据点击率排在最后面,

总来说就是:给了越多钱的排最前,而且是在有效时间内,不给钱的按照点击率排后面。。。

给出以下字段:表(company)
有效时间oktime(1=有效;0=无效)
钱money
点击count
审核commend

奇怪的是我按照这样得出结果
select * from(
select * from company where oktime=1 and commend=1 order by money desc
)a
union
select * from(
select * from company where oktime=0 and money=0 order by count desc
)b
当select * from company where oktime=1 and commend=1 order by money desc
没有数据出来,只有
select * from company where oktime=0 and money=0 order by count desc
有数据的时候却不能按照 order by count desc来排,而是升序排
搞不懂union 怎样用了
如果用union all
select * from(
select * from company where oktime=1 and commend=1 order by money desc
)a
这里面的order by money desc 没有生效啊

union只是将两个结果联结起来一起显示,并不是联结两个表…………

如果要达到你所说的那种效果,那么用union all