Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql SQL按百分比和时间选择项_Mysql_Sql - Fatal编程技术网

Mysql SQL按百分比和时间选择项

Mysql SQL按百分比和时间选择项,mysql,sql,Mysql,Sql,这是我的SQL Select,在30分钟内没有90%的筛选 SELECT id, name, price, pricebefore, link, imagelink, updated, site, siteid FROM items WHERE (case when pricebefore3 is NULL then pricebefore else pricebefore3*1.5 end) >= pricebefore AND price < pricebefore AND

这是我的SQL Select,在30分钟内没有90%的筛选

SELECT id, name, price, pricebefore, link, imagelink, updated, site, siteid FROM items 
WHERE (case when pricebefore3 is NULL then pricebefore else pricebefore3*1.5 end) >= pricebefore 
AND price < pricebefore 
AND isbn != -1 
AND (100-(price/pricebefore)*100) > 80 
ORDER BY updated DESC 
LIMIT 25 
OFFSET 0
从项目中选择id、名称、价格、pricebefore、链接、图像链接、更新、站点、站点id
其中(pricebefore3为空的情况下,则pricebefore其他情况下pricebefore3*1.5结束)>=pricebefore
价格比以前低
还有isbn!=-1.
和(100-(价格/价格前)*100)>80
按更新描述订购
限制25
偏移量0
它工作得很好,但我有一个问题,超过90%的项目必须是30分钟前

SELECT id, name, price, pricebefore, link, imagelink, updated, site, siteid FROM items 
WHERE (case when pricebefore3 is NULL then pricebefore else pricebefore3*1.5 end) >= pricebefore 
AND price < pricebefore 
AND isbn != -1 
AND (100-(price/pricebefore)*100) > 80 
AND ((100-(price/pricebefore)*100) > 90 AND updated < NOW() - INTERVAL 30 MINUTE)
ORDER BY updated DESC 
LIMIT 25 
OFFSET 0
从项目中选择id、名称、价格、pricebefore、链接、图像链接、更新、站点、站点id
其中(pricebefore3为空的情况下,则pricebefore其他情况下pricebefore3*1.5结束)>=pricebefore
价格比以前低
还有isbn!=-1.
和(100-(价格/价格前)*100)>80
和((100-(价格/价格之前)*100)>90并更新
所以我试了这个。但这只给了我超过90%的物品

我需要所有项目(也超过90%),但如果有一个项目超过90%,它必须是30分钟旧。在90%以下,它也可能是1秒前的。。。但90%以上我只需要30分钟以上的物品

SELECT id, name, price, pricebefore, link, imagelink, updated, site, siteid FROM items 
WHERE (case when pricebefore3 is NULL then pricebefore else pricebefore3*1.5 end) >= pricebefore 
AND price < pricebefore 
AND isbn != -1 
AND (100-(price/pricebefore)*100) > 80 
AND ((100-(price/pricebefore)*100) > 90 AND updated < NOW() - INTERVAL 30 MINUTE)
ORDER BY updated DESC 
LIMIT 25 
OFFSET 0

所以结果会给我所有的项目,但如果有超过90%的项目,我只想要超过30分钟的项目(仅针对90%+)

您需要的项目,或者如下所示:

.....
.....
( ((100-(price/pricebefore)*100) > 80  and (100-(price/pricebefore)*100) < 90)
 OR
((100-(price/pricebefore)*100) > 90 AND updated < NOW() - INTERVAL 30 MINUTE) )
.....
.....
。。。。。
.....
(((100-(价格/价格之前)*100)>80和(100-(价格/价格之前)*100)<90)
或
((100-(价格/价格之前)*100)>90并更新
您可以替换这些条件:

AND (100-(price/pricebefore)*100) > 80 
AND ((100-(price/pricebefore)*100) > 90 AND updated < NOW() - INTERVAL 30 MINUTE)

共享一个示例数据集和预期结果。我只需要WHERE子句((100-(price/pricebefore)*100)>90并更新