查詢倒數1-4條數據
今天弄了半個小時才做出自己需要的效果
(當然也可以查詢非倒數的1–4條數據)
SQL語句:
1、不需要寫字段,直接根據表來查詢倒數數據
select * from commoditytb order by commoditytb.commodityId desc limit 0,4
【order by commoditytb.commodityTypeId desc limit 0,4 】這一句就是獲取倒數數據,我這裏獲取倒數4條數據,想獲取幾條就把4換成你需要獲取的數據條數
【order by commoditytb.commodityTypeId desc limit 4,? 】這一句就是不獲取倒數數據,我這裏不獲取倒數4條數據,想不獲取幾條就把4換成你不需要獲取的數據條數, “?” 問號 是數據表總行數
SQL語句:
2、需要寫字段和鏈接其他表、還有根據條件來查詢倒數數據
select commoditytb.commodityId, commoditytb.commodityTypeId, commoditytb.commodityName, commoditytb.sellPrice, commoditytb.getPoints,
commoditytb.stockNumber, commoditytb.produceNumber, commoditytb.factoryName, commoditytb.distinguishId, commoditytb.factoryAdress, commoditytb.factoryConnection,
commoditytb.chargeMixture, commoditytb.qualityDate, commoditytb.netContent, commoditytb.packWay, commoditytb.brank, commoditytb.layInWay, commoditytb.commodityImage, commoditytb.productID,
commoditytb.soldOutBit, commoditytb.barCode, commoditytb.productID, commodity_typetb.commodityTypeName
from commoditytb INNER JOIN commodity_typetb ON commoditytb.commodityTypeId = commodity_typetb.commodityTypeId where commoditytb.soldOutBit != 0 order by commoditytb.commodityId desc limit 0,4