gpt4 book ai didi

mysql - 来自多个可能组的底部 N

转载 作者:行者123 更新时间:2023-11-30 23:06:22 25 4
gpt4 key购买 nike

<分区>

考虑到插入了多个类别或类型,我需要从表中获取最后的 N 个值。

我的 table :

CREATE TABLE `Table1` (
`name` VARCHAR(250) NOT NULL,
`total` INT(11) NOT NULL,
`type` INT(11) NOT NULL
)
ENGINE=InnoDB;

一些值:

|| *name*       || *total*  || *type*   ||

|| Clock || 12 || 103 ||

|| Brief Case || 21 || 103 ||

|| Pencil || 34 || 103 ||

|| Lollypop || 45 || 103 ||

|| Notebook || 67 || 142 ||

|| Rubber Band || 3 || 143 ||

|| Smartphone || 1 || 143 ||

到目前为止我得到了什么:

SELECT name,total from Table1 ORDER BY TOTAL ASC LIMIT 3 where type=143;

但我需要通过一次查询为每个类别获得相同的结果。

试过这个:

SELECT name,total from Table1 ORDER BY TOTAL ASC LIMIT 3 GROUP BY type;

但这是错误的。正如预期的那样,我只从所有记录中检索了 3 条记录,而不是从每个类别中检索了 3 条记录。

[可能重复] Mysql selecting (n) rows of each occurrance

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com