在这里真的很难过,所以任何建议将不胜感激。
我在clients
表中,我有ID
= 257 的客户端的以下记录:
SELECT ref, ID, client_name, data_1 FROM clients WHERE ID = 257
+------+-----+-------------+--------+
| ref | ID | client_name | data_1 |
+------+-----+-------------+--------+
| 1123 | 257 | Client257 | 0 |
| 1124 | 257 | Client257 | 163 |
+------+-----+-------------+--------+
现在,如果我在字段中添加一个简单的 MAX() ref
,我会得到:
SELECT MAX(ref), ID, client_name, data_1 FROM clients WHERE ID = 257
+------+-----+-------------+--------+
| ref | ID | client_name | data_1 |
+------+-----+-------------+--------+
| 1124 | 257 | Client257 | 0 |
+------+-----+-------------+--------+
我应该得到:
+------+-----+-------------+--------+
| ref | ID | client_name | data_1 |
+------+-----+-------------+--------+
| 1124 | 257 | Client257 | 163 |
+------+-----+-------------+--------+
任何人都可以解释一下吗?我应该怎么做才能得到想要的结果?
编辑:
SHOW CREATE TABLE clients
根据@Ilion的要求添加了输出:
CREATE TABLE `clients` (
`ref` int(11) unsigned NOT NULL AUTO_INCREMENT,
`ID` int(11) unsigned NOT NULL,
`client_name` varchar(75) DEFAULT NULL,
`data_1` int(11) unsigned NOT NULL DEFAULT '0',
`last_updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY `ref` (`ref`)
) ENGINE=MyISAM AUTO_INCREMENT=1135 DEFAULT CHARSET=utf8