每對2排的說,我已經得到了以下兩個表:選擇日期時間在表
CREATE TABLE `playerjoins` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`globalId` int(11) NOT NULL,
`date` datetime NOT NULL,
`serverId` int(11) NOT NULL,
`playerId` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `globalId` (`globalId`),
KEY `date` (`date`),
KEY `serverId` (`serverId`),
KEY `playerId` (`playerId`),
CONSTRAINT `playerjoins_ibfk_1` FOREIGN KEY (`serverId`) REFERENCES `servers` (`serverId`),
CONSTRAINT `playerjoins_ibfk_2` FOREIGN KEY (`playerId`) REFERENCES `players` (`playerId`)
) ENGINE=InnoDB AUTO_INCREMENT=64983 DEFAULT CHARSET=latin1
CREATE TABLE `playerleaves` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`globalId` int(11) NOT NULL,
`date` datetime NOT NULL,
`serverId` int(11) NOT NULL,
`playerId` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `globalId` (`globalId`),
KEY `date` (`date`),
KEY `serverId` (`serverId`),
KEY `playerId` (`playerId`),
CONSTRAINT `playerleaves_ibfk_1` FOREIGN KEY (`serverId`) REFERENCES `servers` (`serverId`),
CONSTRAINT `playerleaves_ibfk_2` FOREIGN KEY (`playerId`) REFERENCES `players` (`playerId`)
) ENGINE=InnoDB AUTO_INCREMENT=45676 DEFAULT CHARSET=latin1
而且,開始的時候,我想選擇每行對,通過date ASC, globalId ASC
訂購。
我將如何做到這一點?此外,爲了獲取信息,我想用它來獲取(僞代碼)row1.datetime, row2.datetime
並在我的查詢中再次使用它。
實施例的數據,使用一些更爲抽象的對象表示法:
假定以下是一個特定玩家的結果的數據:
- Playerjoin_1
- Playerleave_1
- Playerjoin_2
- Playerleave_2
然後,我要爲(子)查詢輸出創建以下行:
- (Playerjoin_1,Playerleave_1)
- (Playerjoin_2,Playerleave_2)
你的意思是「我想選擇每一對行」? :O – Manu
@Manu在OP中闡明瞭它。 – skiwi