数据库中不等于怎么写大于等于的条件怎么写

SQL语句中大于小于的判断
[问题点数:40分,结帖人a5946555]
SQL语句中大于小于的判断
[问题点数:40分,结帖人a5946555]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
本帖子已过去太久远了,不再提供回复功能。The page is temporarily unavailable
nginx error!
The page you are looking for is temporarily unavailable.
Please try again later.
Website Administrator
Something has triggered an error on your
This is the default error page for
nginx that is distributed with
It is located
/usr/share/nginx/html/50x.html
You should customize this error page for your own
site or edit the error_page directive in
the nginx configuration file
/etc/nginx/nginx.conf.假设的应用场景&
我假定博客园要在首页为群组开辟一块空间,推广小组,小组能在首页显示的条件有四个:
1.页面点击量大于10w
2.小组人数大于1000
3.小组帖子数大于10000
4.小组在2007年之前创建
现在假定4个条件都满足的小组只有两个,太少了,推广位可以推广10个小组;这时候运营人员要求这4个条件中满足3个但是第4个条件不满足的小组算符合条件的小组,如果4个条件都满足就认为这个小组太火了,不需要在首页推广它了。业务逻辑想清楚了,下一步就该写代码了,数据逻辑层的代码的任务假定交给我了,我要考虑满足4个条件中3个成立的sql怎么写。
为了叙事方便,我们假如小组表的名字为Group,相关的条件字段是Pv,UserCount,PostCount,CreateTime:分别表示小组的点击量,人数,帖子数,创建时间.&
我来写sql语句,上面的四个条件满足至少3个,有多少种情况呢?这是一个组合问题,一共有多少种的公式我已经忘记了,我要根据感觉写写看:
SELECT&*&FROM&Group
WHERE&&(Pv&<span style="font-weight: color: #0000&AND&UserCount&<span style="font-weight: color: #00&AND&PostCount&<span style="font-weight: color: #000&AND&CreateTime&&&<span style="font-weight: color: #070101)&
OR&(Pv&<span style="font-weight: color: #0000&AND&UserCount&<span style="font-weight: color: #00&AND&PostCount&<span style="font-weight: color: #000&AND&CreateTime&&&<span style="font-weight: color: #070101)
OR&(Pv&<span style="font-weight: color: #0000&AND&UserCount&<span style="font-weight: color: #00&AND&PostCount&<span style="font-weight: color: #000&AND&CreateTime&&&<span style="font-weight: color: #070101)
Sqlnm&*&FROM&Group
(CASE&Pv&WHEN&Pv&<span style="font-weight: color: #0000&THEN&<span style="font-weight: color: #&ELSE&<span style="font-weight: color: #&END)&--这是PV的条件成立则为1,否则为0
+(CASE&UserCount&WHEN&UserCount&&&<span style="font-weight: color: #00&THEN&<span style="font-weight: color: #&ELSE&<span style="font-weight: color: #&END)&--用户数条件
+(CASE&PostCount&WHEN&PostCount&&&<span style="font-weight: color: #000&THEN&<span style="font-weight: color: #&ELSE&<span style="font-weight: color: #&END)&--帖子数条件
+(CASE&CreateTime&WHEN&CreateTime&&&<span style="font-weight: color: #070101&THEN&<span style="font-weight: color: #&ELSE&<span style="font-weight: color: #&END)&--时间条件
=&<span style="font-weight: color: #
如果上面的三个表达式加起来值是3就说明恰好满足三个条件,如果是两个条件就是等于2,如果扩展为n个条件m个条件成立也很容易写,很容易维护、修改。&
这是一个sql条件语句的技巧,希望对你有用。
本文假设的场景纯属虚设,请勿遐想。J
非常感谢韦恩卑鄙 在回复中提出了一种非常好的用法,可以给每个条件加上不同的优先级排序,代码如下:
SELECT&*&FROM&GROUP&WHERE&(
CASE&a&WHEN&a&<span style="font-weight: color: #&THEN&<span style="font-weight: color: #00&ELSE&<span style="font-weight: color: #&END&+&
CASE&b&WHEN&b&<span style="font-weight: color: #&THEN&<span style="font-weight: color: #0&ELSE&<span style="font-weight: color: #&END&+&
CASE&c&WHEN&C&<span style="font-weight: color: #&THEN&<span style="font-weight: color: #&ELSE&<span style="font-weight: color: #&END&+&
CASE&d&WHEN&d&<span style="font-weight: color: #&THEN&<span style="font-weight: color: #&ELSE&<span style="font-weight: color: #&END&
)&&&<span style="font-weight: color: #1
ORDER&BY&(
CASE&a&WHEN&a&<span style="font-weight: color: #&THEN&<span style="font-weight: color: #00&ELSE&<span style="font-weight: color: #&END&+&
CASE&b&WHEN&b&<span style="font-weight: color: #&THEN&<span style="font-weight: color: #0&ELSE&<span style="font-weight: color: #&END&+&
CASE&c&WHEN&C&<span style="font-weight: color: #&THEN&<span style="font-weight: color: #&ELSE&<span style="font-weight: color: #&END&+&
CASE&d&WHEN&d&<span style="font-weight: color: #&THEN&<span style="font-weight: color: #&ELSE&<span style="font-weight: color: #&END&)
阅读(...) 评论()

我要回帖

更多关于 excel条件大于等于 的文章

 

随机推荐