我需要使用MAX从表中选择2个值之间的数据,因为每个SID都有不同的VID,我需要获取一些数据,如下所示。
我需要从SID中获取这些VID:
SID 1: "5, 6, 7, 8"<br/>
SID 2: "2, 3, 4, 5"<br/>
SID 3: ""<br/>
SID 4: "3, 4, 5, 6"<br/>
我的代码:
$sql = mysqli_query($con, "SELECT * FROM `tests` WHERE `VID` BETWEEN MAX(`VID`)-7 AND MAX(`VID`)-4 ORDER BY `SID` ASC, `VID` ASC");
我的桌子:
INSERT INTO `tests` (`ID`, `SID`, `VID`, `Text`) VALUES
(1, 1, 1, 'test'),
(2, 1, 2, 'test'),
(3, 1, 3, 'test'),
(4, 1, 4, 'test'),
(5, 1, 5, 'test'),
(6, 1, 6, 'test'),
(7, 1, 7, 'test'),
(8, 1, 8, 'test'),
(9, 1, 9, 'test'),
(10, 1, 10, 'test'),
(11, 1, 11, 'test'),
(12, 2, 1, 'test'),
(13, 2, 2, 'test'),
(14, 2, 3, 'test'),
(15, 2, 4, 'test'),
(16, 2, 5, 'test'),
(17, 2, 6, 'test'),
(18, 2, 7, 'test'),
(19, 2, 8, 'test'),
(20, 3, 1, 'test'),
(21, 3, 2, 'test'),
(22, 3, 3, 'test'),
(23, 4, 1, 'test'),
(24, 4, 2, 'test'),
(25, 4, 3, 'test'),
(26, 4, 4, 'test'),
(27, 4, 5, 'test'),
(28, 4, 6, 'test'),
(29, 4, 7, 'test'),
(30, 4, 8, 'test'),
(31, 4, 9, 'test');
谢谢♥:)
答案 0 :(得分:1)
也许不是最好的方法,但这可行:
Xrm.Navigation is undefined
或1班轮:
Xrm.Navigation
答案 1 :(得分:0)
我刚刚找到了,这就是我所需要的
SELECT MAX(vid)-n1 AS max1, MAX(vid)-n2 AS max2 FROM `tests` GROUP BY sid
感谢所有人:)