简体   繁体   English

MySQL查询最低价格

[英]MySQL query for lowest price

We got table with different products when it is displayed on webpage I want to display lowest price first but not <> 0 and joint to price = 0 and then join to maximum price with ASC order. 当页面显示在网页上时,我们得到了具有不同产品的表,我想首先显示最低价格,但不显示<> 0,然后显示价格= 0,然后使用ASC订单显示最高​​价格。 I tried to do it with lots of queries.But is it possible to do in one query? 我试图通过很多查询来做到这一点,但是可以在一个查询中做到吗?

for get lowest price you can use this, 为了获得最低的价格,您可以使用它,

select itemcode, price from item where price>0 order by price asc limit 1

Record is for the lowest, for the highest price, change "ASC" to "DESC" 记录是最低价,最高价,将“ ASC”更改为“ DESC”

you can try this 你可以试试这个

 select top * (price) from table
 where price>=0
 order by price 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM