mysql在一条语句中选择最高和最低值与限制

时间:2018-07-23 19:28:55

标签: mysql

我需要从表格价格的表格产品中拉出5个最高价格和5个最低价格。我以为我可以像下面这样在一个stmt中做两个选择,但是我想你不能,因为它是同一张桌子?我完成了类似的stmts,并且可以使用不同的表。

SELECT products.* AS fullcount, (SELECT * FROM products ORDER BY price ASC LIMIT 5) AS highest, (SELECT * FROM products ORDER BY price DESC LIMIT 5) AS lowest FROM products

我在做错什么,还是应该使用其他方法?

1 个答案:

答案 0 :(得分:1)

使用import android.arch.lifecycle.LiveData import com.abubusoft.kripton.android.annotation.BindDao import com.abubusoft.kripton.android.annotation.BindSqlDynamicWhere import com.abubusoft.kripton.android.annotation.BindSqlSelect import com.abubusoft.kripton.android.annotation.BindSqlUpdate import com.abubusoft.kripton.example.rssreader.service.model.Article @BindDao(Article::class) interface DaoArticle { @BindSqlUpdate(where = "id=:id") fun update(id: Long, read: Boolean) @BindSqlSelect fun selectByChannel(@BindSqlDynamicWhere where: String): LiveData<List<Article>> @BindSqlSelect(where = "id=:id") fun selectById(id: Long): List<Article> @BindSqlSelect(where = "id in (:ids)") fun selectByChannelUd(ids: List<Long>): List<Article> @BindSqlSelect(where = "guid=:guid") fun selectByGuid(guid: String): Article } 合并获得最高和最低行的查询结果。

UNION