请在底部查看最后的编辑
我在phpMyAdmin中使用MySQL进行以下查询:
(SELECT
id,
name,
rank1,
rank2
FROM rank_list
LEFT JOIN names ON names.id = rank_list.name_id
WHERE type = "typeA"
ORDER BY rank1
LIMIT 50)
UNION ALL
(SELECT
id,
name,
rank1,
rank2
FROM rank_list
LEFT JOIN names ON names.id = rank_list.name_id
WHERE type = "typeB"
ORDER BY rank2
LIMIT 50)
rank1
的{{1}}的前50名排名,并将其与typeA
的{{1}}的前50名排名合并。rank2
周围加上括号,因为我将
typeB
和SELECT
都声明。问题
将LIMIT
应用于两个查询时出现以下错误:
ORDER BY
我真的不在这里...可能引起这一问题的原因是,如果UNION
(与A non-numeric value encountered
相同,并且在{{1} rank1
。
还是这里还有其他东西?
编辑:
当我不对其应用-1
时,它确实可以工作
编辑2
我发现执行以下操作(使用括号)时,也会遇到相同的错误:
type = "typeB"
答案 0 :(得分:0)
尝试使用强制转换为数据类型
(SELECT
id,
name,
cast(rank1 AS SIGNED ),
cast(rank2 AS SIGNED )
FROM rank_list
LEFT JOIN names ON names.id = rank_list.name_id
WHERE type = "typeA"
ORDER BY rank1
LIMIT 50)
UNION ALL
(SELECT
id,
name,
cast(rank1 AS SIGNED ),
cast(rank2 AS SIGNED )
FROM rank_list
LEFT JOIN names ON names.id = rank_list.name_id
WHERE type = "typeB"
ORDER BY rank2
LIMIT 50)
答案 1 :(得分:0)
我无法复制您的问题
drop table if exists rank_list,names;
create table rank_list
(id int,name_id int,rank1 int,rank2 int,type varchar(10));
create table names
(id int, name varchar(3));
insert into rank_list values
(1,1,1,1,'typea'),(2,2,3,1,'typea'),
(2,2,1,1,'typeb');
insert into names values
(1,'aaa'),(2,'bbb');
(SELECT
rank_list.id,
name,
rank1,
rank2
FROM rank_list
LEFT JOIN names ON names.id = rank_list.name_id
WHERE type = "typeA"
ORDER BY rank1 desc
LIMIT 50)
UNION ALL
(SELECT
rank_list.id,
name,
rank1,
rank2
FROM rank_list
LEFT JOIN names ON names.id = rank_list.name_id
WHERE type = "typeB"
ORDER BY rank2 desc
LIMIT 50);
+------+------+-------+-------+
| id | name | rank1 | rank2 |
+------+------+-------+-------+
| 2 | bbb | 3 | 1 |
| 1 | aaa | 1 | 1 |
| 2 | bbb | 1 | 1 |
+------+------+-------+-------+
3 rows in set (0.00 sec)
请注意,我具有完全合格的ID,如果您的型号不同,那么如果您没有更多的输入,任何答案或评论都将是猜测。