我正在开发一个在线考试系统,如果用户的分数在管理员设置的范围内,我想从数据库中获取数据。
范围是动态的,由管理员设置。
示例:
表格字段值:
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/