-
No way. So the simple question is what it looks like.
Let's say your table name is a
select m,min(n) from a group by m
-
select m,n from table where id in(select m,min(id) from table group by m)
I'm not sure, but I've been using Orale a lot lately
Oracle has a rowid that is unchanged.,SQL should also have it.,I don't know if it's an ID.,The landlord can check it himself!
-
distinct + sort.
You don't need top, you can sort it directly.
example:
select distinct m from table order by n desc"
-
I summarized the articles that selected the first few pieces of data and randomly extracted them, and there are various common databases.
-
Is there any pattern to 5 out of 15? If it's random, that's too difficult, right?
It's still a big table, first select the first 15 rows, and then select the 5 rows of data in 11-15 rows.
Also, what database are you using? sqlserver, oracle, or other.
-
Please describe the specific points, thanks!
-
A few commonly used databases are written as follows:
1. MSSQL database.
select top 1 * from table2 and oracle database.
select * from table where rownum < 2
3. MySQL database:
select * from table limit 0, 1 (where the keyword limit startid,rownum is like this: it means that a total of rownum records are queried starting from the startid + 1 line.)
-
select top 1 company id,bargain man,bargain type,bargain time from bargain(database table) where bargain time 《Time1 and bargain time> Time2
-
This can be solved with the row number.
1. For example, the data in the EMP table are as follows:
2. Now to find out the data arranged from empno from small to large, the second to the fourth, can be used as follows:
select t.* from
select emp.*,row_number() over (order by empno) rn from emp) t
where rn between 2 and 4;
3. Query result:
-
You can use limit to solve the problem, for example, query the 2nd to 4th records in the jbqk table. select * from jbqk limit 1,3;- The comma is preceded by an offset, followed by a display of several messages.
-
You can try sorting and then group by.
-
select top 1 * from the table name where (followed by the constraints on your query results).
-
Use the windowing function.
select * from
select t.*,row_number() over(partition by group_column order by order_column) rn
from table t )
where rn <=5 ;
The grouping and sorting criteria can be modified according to your needs.
-
Group first, and then take the first 5 entries of each group.
-
Use groups in the self-query, and take 5 entries outside.
-
For example, write an SQL statement to retrieve records 21 and 30 in Table S (SQL Server uses the auto-growing ID as the primary key, and the ID may not be contiguous).
Method 1: Select top10 * from s
where id>(select max(id) from (select top20 id from s ) as s)
Method 2: select top10 * from s where id is not in (select top20 id from s).
-
interval, you need to use and to replace the double condition, not directly 22 and id<5;
Explanation: AND indicates that the condition must be met at the same time, that is, the query ID is greater than 2 and less than 5 ( 2
-
consumetime between cast(getdate() as int) and getdate()
getdate() is the current system time.
getdate() is the time 12 hours ago.
If you want to query a fixed morning or noon data, if you use SQL Query Analyzer, you can directly replace the query time period.
If you want to inquire about it at noon today, you can use it.
consumetime between 2008-10-21 8:00:00 and 2008-10-21 14:00:00
If it is other software, you can set the condition after consumetime as a parameter, query the data between 1900-1-1 1900-1-1 8:00:00 when you select morning, and replace the parameter with 1900-1-1 8:
00, the date must be changed, and the time can be set to be fixed.
-
Have you done pagination, and the pagination SQL is not exactly the same as your needs!
-
If you look at articles 5---8.
select * from (
select top 1 * from nsort order by nsort_id desc
t where >5 and rownum <8;
If it is a ground, select * from (
select top 1 * from nsort order by nsort_id desc
t where in (5,8,10)
There are a lot of wild monsters in the Honor of Kings mobile game, and it is precisely because of these wild monsters that there is a hero position like jungle, and if you want to play the jungler position well, it is very necessary to understand the refresh time of the wild monsters. How many minutes is the first Juggernaut refresh time for? How many minutes does the Glory of Kings refresh? >>>More
China now has a lot of transportation modes, and with the construction and laying of high-speed rail, China's railway network is also more dense. There are some of the longest and most expensive railways in today's railways, but do you know which one was the earliest in our country?
01 Chengdu-Chongqing Railway.
The Chengdu-Chongqing Railway is the first railway trunk line in southwest China, the first railway built after the founding of the People's Republic of China, and an unimaginable miracle in any era before the founding of the People's Republic of China, and is of great significance in the history of China's railway development. Start and end: from Chengdu City, Sichuan Province in the northwest to Chongqing in the southeast. >>>More
On September 24, 1909, the first railway designed in China, the Beijing-Zhangjiakou Railway, was opened to traffic, and in April 1905, Zhan Tianyou was appointed as the chief engineer of the Beijing-Zhangjiakou Railway. With a total length of more than 200 kilometers, the Beijing-Zhangjiakou Railway officially started construction in August 1905 and opened to traffic on September 24, 1909. It was the first railway designed and built by the Chinese. >>>More
Generally speaking, this is normal.
1.Because there is pressure underwater. The respiratory system of goldfish is not the same as that of individual goldfish if they do not maintain air pressure. >>>More