mysql in 查询, 里面的每个条件都指定返回条数,能否实现,怎么写?
高洛峰
高洛峰 2017-04-17 16:13:28
0
2
775

mysql in 查询, 里面的每个条件都指定返回条数,能否实现,怎么写?

SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1,value2)

table_name 里面包含value1和value2的值有很多条,能否指定返回条数。

类似:

select * from table_name where column_name = value1 limit 5;
select * from table_name where column_name = value2 limit 5;

或有其他方法实现这个查询?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
小葫芦

It is the conversion of or/in/union all. The performance is also better than union all, and it can also meet the requirement of returning the specified number of items as you said.

(select * from table_name where column_name = value1 limit 5)
union all
(select * from table_name where column_name = value2 limit 5);
小葫芦

Your sql seems inconsistent with your description
SELECT column_name(s),count(column_name(s))
FROM table_name
WHERE column_name(s) IN (value1,value2,...)
group by column_name(s) )

There is nothing logically wrong with this way of writing, but please take a look at the execution plan after writing it. If I remember well, the efficiency of mysql's in is not high. If it is a single table, I can't think of anything good. Idea

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!