我试图仅获得这四个突出显示的结果。我尝试将它们分组,但仍未获得所需的结果。
查询是:-
Set @filter := 0.00;
SELECT autorates2.ID, autorates2.Car, autorates2.Origin , autorates2.Destination, autorates2.Carrier,
@FuelLevy := ( autorates2.Buy * Carrier.FuelLevy) + autorates2.Buy AS 'AfterFuelLevy',
@GST :=(@FuelLevy * 0.10) + @FuelLevy AS 'AfterGST',
@filter := (Select Margin.MarginPer from Margin where @GST between Margin.Low and Margin.High ),
@Margin := (@filter * @GST) + @GST AS 'Sell',
autorates2.OriginType, autorates2.DestinationType, CONCAT(autorates2.OriginType, autorates2.DestinationType) as'ser'
from Margin, Carrier
RIGHT JOIN autorates2 on autorates2.Carrier = Carrier.Carrier
Where autorates2.Origin = 'Melbourne' AND autorates2.Destination = 'Sydney' AND autorates2.Car = '4WD/Van' AND Carrier.Disabled = 0 AND autorates2.GoodsAllowed = 0
Group by ser
ORDER by MIN(Sell),ser
我得到的输出是突出显示的结果是错误的地方:-
表1:
表2:
表3:
答案 0 :(得分:0)
按以下方式使用相关子查询,因为您没有共享所有源列名称,所以我猜价格是一列
select * from yourtable t1 where price in
(
select min(price) from yourtable t2 where t1.car=t2.car
and t1.depot=t2.depot and t1.door=t2.door
and t1.destinationtype=t2.destinationtype and t1.ser=t2.ser
)