Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Which SQL statements are commonly used?

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail what the commonly used SQL sentences refer to, and the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

The 1.SQL insert statement gets the automatically generated incremental ID value

The code is as follows: insert into Table1 (Name,des,num) values ('ltp','thisisbest',10); select @ @ identity as' Id'

2. If the implementation is 1 or 0, you want to show it as male or female.

The code is as follows: select name,Sex= (case Sex when'1' then 'male' when'0' then 'female' end) from Tablename

3. Nested subquery

The code is as follows: select a dint bje c from Table1 where an IN (select a from Table2)

4. Show the article, the author and the last reply time

The code is as follows: select a.title.username from tablename a b.adddate from tablename a, (select max (title) adddate from tablename where tablename.title=a.title) b

5. An example of randomly extracting bar records

The code is as follows: SQL Server:Select Top 10 * From Tablename Order By NewID () Access:Select Top 10 * From Tablename Order By Rnd (ID) Rnd (ID) where ID is an automatic numbering field, which can be done with any other numeric value, such as using the name field UserName Select Top 10 * From table Order BY Rnd (Len (UserName)) MySql:Select * From table Order By Rand () Limit 10

6. Find records with the same attributes in the same table

The code is: select UserID from Accounts_Users where UserName is not null group by UserID having count (*) > 1

7. Query the corresponding data of all products in the category

The code is as follows: SELECT CategoryName,ProductName FROM Categories LEFT JOIN Products ON Categories.CategoryID = Products.CategoryID

8. Query user information with numbers between 2 and 5 by range

The code is as follows: select * from UserValue where UserID between 2 and 5

9. Schedule reminder 5 minutes in advance

The code is as follows: Select * from TabSchedule where datediff (minute,getdate (), start time)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

  • Mybatis oracle bulk insert

    Insert into INFOTOEMPLOEEselect INFO_EMPLOEES.NEXTVAL,A.* from (

    © 2024 shulou.com SLNews company. All rights reserved.

    12
    Report