Home > database >  Mysql search queries
Mysql search queries

Time:09-21

Data structure is as follows:

Id name price origin

Data 1 88.00 sina
2, 18.00 2 data baidu
3 data 3 58.00 Google
4 data 4 78.00 Google
5 data 98.00 baidu
6 data 18.00 baidu
7 data 7 28.00 ask
Data 8 August 38.00 ask
9 data 9 38.00 sina
.
1004 data of 1004 78.00 Google
1005 data of 1005 baidu
98.001006 data of 1006 baidu
18.001007 data of 1007 28.00 ask
1008 data of 1008 38.00 ask
1009 data of 1009 sina
38.00
I want to search query results meet such conditions:
10 per page after page, this article 10 the origin of data must be in the "sina, baidu, Google, ask", a few concrete can be random ;

CodePudding user response:

The first page:
Select id, name, price, origin from the TAB where id> 0 and origin in (' sina ', 'baidu', 'Google', 'ask') order by id limit 10;
Take note of the last line of the page id value, the assumption for num,
The second page:
Select id, name, price, origin from the TAB where id> Num and origin in (' sina ', 'baidu', 'Google', 'ask') order by id limit 10;
By analogy,

CodePudding user response:

reference 1st floor by the stars of a cold response:
the first page:
Select id, name, price, origin from the TAB where id> 0 and origin in (' sina ', 'baidu', 'Google', 'ask') order by id limit 10;
Take note of the last line of the page id value, the assumption for num,
The second page:
Select id, name, price, origin from the TAB where id> Num and origin in (' sina ', 'baidu', 'Google', 'ask') order by id limit 10;
By analogy,


No, it is concluded that the same, such as data are origin=sina

CodePudding user response:

refer to the second floor plcc123 response:
Quote: refer to 1st floor by the stars of a cold response:

The first page:
Select id, name, price, origin from the TAB where id> 0 and origin in (' sina ', 'baidu', 'Google', 'ask') order by id limit 10;
Take note of the last line of the page id value, the assumption for num,
The second page:
Select id, name, price, origin from the TAB where id> Num and origin in (' sina ', 'baidu', 'Google', 'ask') order by id limit 10;
By analogy,


No, it is concluded that the same, such as are origin=sina data


You mean the data returned must include "sina, baidu, Google, ask" the four?

CodePudding user response:

reference 3 floor by the stars of a cold response:
Quote: refer to the second floor plcc123 response:

Quote: refer to 1st floor by the stars of a cold response:

The first page:
Select id, name, price, origin from the TAB where id> 0 and origin in (' sina ', 'baidu', 'Google', 'ask') order by id limit 10;
Take note of the last line of the page id value, the assumption for num,
The second page:
Select id, name, price, origin from the TAB where id> Num and origin in (' sina ', 'baidu', 'Google', 'ask') order by id limit 10;
By analogy,


No, it is concluded that the same, such as are origin=sina data


You mean the data returned must include "sina, baidu, Google, ask" the four?

Yes, as long as there is this article 10 data in the database must contain the four, six other random data, according to the or can do this every * 2, and so is this article four * 2-8 data, the other two would be even better at random

CodePudding user response:

Have a great god in? Ask for help!

CodePudding user response:

A clumsy way,
Select * from (select * from test where origin='baidu' limit order by id 0, 2) a
Union all
Select * from (select * from test where origin='Google' limit order by id 0, 2) b
Union all
Select * from (select * from test where origin='sina' limit order by id 0, 2) c
Union all
Select * from (select * from test where origin='ask' limit order by id 0, 2) d
Union all
Select * from (select * from test where originnot in (' baidu ', 'Google', 'sina', 'ask') limit order by id 0, 2) e;

CodePudding user response:

refer to 6th floor by the stars of a cold response:
a clumsy way,
Select * from (select * from test where origin='baidu' limit order by id 0, 2) a
Union all
Select * from (select * from test where origin='Google' limit order by id 0, 2) b
Union all
Select * from (select * from test where origin='sina' limit order by id 0, 2) c
Union all
Select * from (select * from test where origin='ask' limit order by id 0, 2) d
Union all
Select * from (select * from test where originnot in (' baidu ', 'Google', 'sina', 'ask') limit order by id 0, 2) e;

Ok, thank you

CodePudding user response:

refer to 6th floor by the stars of a cold response:
a clumsy way,
Select * from (select * from test where origin='baidu' limit order by id 0, 2) a
Union all
Select * from (select * from test where origin='Google' limit order by id 0, 2) b
Union all
Select * from (select * from test where origin='sina' limit order by id 0, 2) c
Union all
Select * from (select * from test where origin='ask' limit order by id 0, 2) d
Union all
Select * from (select * from test where originnot in (' baidu ', 'Google', 'sina', 'ask') limit order by id 0, 2) e;


nullnullnullnullnullnullnullnullnullnullnull
  • Related