Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.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 最低价格_Mysql_Sum_Min - Fatal编程技术网

Mysql 最低价格

Mysql 最低价格,mysql,sum,min,Mysql,Sum,Min,我有一个公寓日历表,用于向用户显示每天的价格。 在此表中,一些公寓包括要出租的房间: 表列/记录示例: id_apart | id_room | date | price | promo_price 1 | 1 | 03-03-2013 | 20.00 | 0 1 | 1 | 04-03-2013 | 20.00 | 0 1 | 2 | 03-03-2013 | 50.00 | 45.00 1

我有一个公寓日历表,用于向用户显示每天的价格。 在此表中,一些公寓包括要出租的房间:

表列/记录示例:

id_apart | id_room | date       | price | promo_price
1        |    1    | 03-03-2013 | 20.00 | 0
1        |    1    | 04-03-2013 | 20.00 | 0
1        |    2    | 03-03-2013 | 50.00 | 45.00
1        |    2    | 04-03-2013 | 50.00 | 45.00
因此,我想得到一个字符串,其中包含'price'和'promo_price',并将两个日期之间公寓/房间的最低价格总和连接起来

这个查询是对公寓所有房间价格的总和,我不知道如何在这个问题上使用MIN,只对最便宜房间的价格进行总和:

select 
    concat(sum(if(promo_price>0,promo_price,price)), 
    "---",
    sum(price)) 
from 
    apart 
where 
    id_apart=215 
    and date>= "2013-03-03" 
    and date<"2013-03-05"
此查询的结果是: 90-140

图例:第一个字符串编号是“促销价格”的总和;“价格”的第二个数字总和

请试试这个

select concat(promo_price, "--", price) from apart 
where id_apart=215 and date >= "2013-03-03" and date < "2013-03-05" 
and (promo_price + price)) = (select min(promo_price + price) from apart);
select concat(if(promo_price>0, 'true', sum(promo_price)),'---', sum(price))
from aprt where id_apart = 215 and date between "2013-03-03" and "2013-03-05"
我想这就是你要找的吗

   select if(promo_price = 0,concat(sum(price),"---", sum(price)) ,sum(price)) as pri
  from apart  
   where id_apart=1 and `date`>= "03-03-2013" and `date` < "05-03-2013"
   and promo_price = 0
40-40


注意,我在上面的例子中将id_分开=1。

这是你想要的答案吗

select 
concat(sum(if(promo_price>0,promo_price,price)), 
"---",
sum(price)) from apart group by id_room 
having sum(price) + sum(promo_price) = 
(select min(sum(price) + sum(promo_price)) from apart where id_apart =1 
group by id_room);

输出:40-40

你想要得到什么结果?我的答案被结果编辑了。这就是我得到的结果。我只想退回最便宜房间的房款。我应该得到:40-40
select 
concat(sum(if(promo_price>0,promo_price,price)), 
"---",
sum(price)) from apart group by id_room 
having sum(price) + sum(promo_price) = 
(select min(sum(price) + sum(promo_price)) from apart where id_apart =1 
group by id_room);