0

我有一个公寓日历表,用于向用户显示每天的价格。在这张桌子上,一些公寓包括房间(id_room)出租:

表列/记录示例:

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

图注:第一个字符串数字是 'promo_price' 的总和;“价格”的第二个数字总和

4

4 回答 4

0
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);
于 2013-03-07T12:52:13.183 回答
0

请试试这个

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"
于 2013-03-07T12:59:59.403 回答
0

我想这就是你要找的

   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

输出。

   PRIS

40---40

obs请注意,我从您上面的示例中制作了 id_apart=1 。

于 2013-03-07T13:02:12.353 回答
0

这是你在寻找的答案吗?

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

于 2013-03-08T09:10:10.287 回答