{mysql}使用交叉连接选择
我现在对我的sql选择有点困惑。 我得到了类似于:{mysql}使用交叉连接选择,mysql,select,join,Mysql,Select,Join,我现在对我的sql选择有点困惑。 我得到了类似于: CREATE TABLE IF NOT EXISTS `a` ( `id` int(11) NOT NULL, `ip` int(11) unsigned NOT NULL, `name` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 数据如下:
CREATE TABLE IF NOT EXISTS `a` (
`id` int(11) NOT NULL,
`ip` int(11) unsigned NOT NULL,
`name` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
数据如下:
INSERT INTO `a` (`id`, `ip`, `name`) VALUES
(1, 2147483647, 'foobar'),
(2, 2372224735, 'foobar2');
因此,我想将另一个表附加到
select * from a
指:
select * from a cross join (select * from b where ip <= a.ip order by ip desc limit 1)
但它不起作用,我不知道如何修复它:/
有什么想法吗
提前谢谢
select * from a cross join (select * from b where ip <= a.ip order by ip desc limit 1) aaa
我刚刚添加了aaa作为派生表的名称,这是必需的,即使它没有被引用。b的模式是什么,您期望的输出是什么?表b的模式包含ip详细信息,我想将内容附加到表A的选择行,为什么不简单的左/右/内部连接,为什么交叉连接?为什么附加?我需要限制where子句的结果限制1,我并没有找到任何方法来实现这一点