gpt4 book ai didi

php - MySQL:如何在mysql中选择范围?

转载 作者:行者123 更新时间:2023-11-29 21:12:23 26 4
gpt4 key购买 nike

我正在开发一个在线考试系统,如果用户的分数在管理员设置的范围内,我想从数据库中获取数据。

范围是动态的,由管理员设置。

示例:

表格字段值:

outcome_id | outcome_range
1 | 2,5
2 | 6,10
3 | 11,15

用户:

如果用户得到 3 分,它将从表中获取数据行结果 id 1,因为分数在 2-5 范围内。

最佳答案

您可以分隔范围

表格

outcome_id | min_outcome | max_outcome
1 | 2 | 5
2 | 6 | 10
3 | 11 | 15

查询

SELECT * FROM table_name WHERE min_outcome <= 3 AND max_outcome >= 3

创建表

CREATE TABLE IF NOT EXISTS `table_name` (
`outcome_id` int(11) NOT NULL AUTO_INCREMENT,
`min_outcome` int(10) NOT NULL,
`max_outcome` int(10) NOT NULL,
PRIMARY KEY (`outcome_id`)
) ;

INSERT INTO `table_name` (`outcome_id`, `min_outcome`, `max_outcome`) VALUES
(1, 2, 5),
(2, 6, 10),
(3, 11, 15);

关于php - MySQL:如何在mysql中选择范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36255519/

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