1T-SQL Simple query statement2 3 Simple query:4 51.The simplest query (check all data)6SELECT * from table name; NOTE: *represents all Columns7SELECT *From info8 92.querying a specified columnTenSelect Code,name from Info One A3.Modify the column name of the result set -Select Code as' Code ', name asNameFrom info -
When we query information in the database, we often need to query the information based on the conditions entered by the user. Some conditions are available, but some conditions are unavailable. Therefore, we need to assemble the condition statements. The following method is compiled based on this situation, hoping to help the reader:
String SQL = "select * fr
(SelectMAXfromorderbydesc; Meaning: First check out the tallest height, exclude the height, then sort the data (descending) and query out the current first piece of data. 2, the query may be the same as the highest height value of the second place, that is, if the height is 182 Several people are also 182 height, The second place is still Select Top 1 * from (selecttop2fromorderbydescOrder by
Query, delete, insert, query, sort SQL statementHere we provide query, delete, insert, query, sort totals sum average max minimum SQL statement OH.Selection: SELECT * FROM table1 whereInserting: INSERT INTO table1 (field1,field2)
Label:In SQL Server, each query will find the shortest path to achieve its own goal. If the database accepts only one connection at a time, only one query is executed. Then the query is, of course, M.F.B. s to complete the work. For most databases, however, multiple queries need to be processed at the same time. Instea
SQL query (Note 2--entity query)Second, the entity queryIf the query returns all of the data columns for a data table, and the data table has a corresponding persisted class map, we convert the query results into entity queries. You can use the multiple overloaded addentity
Label:The first is the problem of fuzzy query, I started with the following conditions: SELECT * from the user where name like '% #value #% '. But how can not, as if also reported wrong. Later on the internet found a solution, is to use $ to replace the # number.1> write: Like '% $value $% ' can be,2> also found another method, but that method I tried for a long time, is not, the method is: like '% ' | | #value # | | '% ', the
SQL statement Optimization-query different rows of the two tables NOT IN, NOT EXISTS, Join query Left Join, existsleft
In actual development, we often need to compare the differences between two or more tables and compare the data that is the same and the data is different. At this time, we can use the following three methods: 1. IN or not in, 2. EXIST or NOTEXIS
[Name],subject,score Here for a good understanding only one column to get the following results With the example of the language accomplishment line train, it is easy to add the other two columns, Select [Name],Chinese =caseWhen subject= ' language ' then score else 0EndMathematics =caseWhen subject= ' math ' then score else 0EndForeign Language =caseWhen subject= ' foreign language ' then score else 0EndFrom StudentscoreGroup BY [Name],subject,score The following is the result of the
Introduction to the Decode () function:Main role: Translation of query results into other values (that is, in other forms of expression, the following examples);How to use:Select decode (ColumnName, value 1, translation value 1, value 2, translation value 2,... Value n, translation value n, default value)From TalbenameWhere ...Where ColumnName is the column defined in the table to be selected,• Explanation of Meaning:Decode (condition, value 1, transl
When converting Oracle queries to SQL queries, you need to pay attention to a lot of issues. The following gives you a detailed analysis of the number trade-offs in converting Oracle queries to SQL queries for your reference.
Number trade-offs
Oracle Database has a TRUNC function, which returns n digits of the m-bit decimal number. If m is omitted, n is 0 digits. The m value can be negative, indicating th
Label:--sal for employee wagesSELECT * from EMP;--Inquire about employee information in the [1500,3000] range of wagesSELECT * from emp where Sal >= and Sal SELECT * from EMP where Sal between and 3000;--The above two sentences have the same effect--Query employee information for wages less than 1500 or greater than 3000SELECT * from emp where Sal SELECT * from emp where Sal is not between and 3000;--The above two sentences have the same effect--
Grouping query of SQL is very useful, but sometimes its features are also annoying. Take a good look at this SQL:
select employer_name, department, max(salary) from employer_salary group by department;
Query the name and salary number of the highest-paying person in each department. Is there a problem with this
Brief introduction
In SQL Server, an index is an enhanced existence, which means that SQL Server can still implement functionality even without indexes. However, indexes can greatly improve query performance in most cases, especially in OLAP. To fully understand the concept of the index, you need to know a lot of the knowledge of the original rationality, includ
Php:It is usually the beginning of the code you want to check to record a time, the end of the record a time. Take the difference value,the efficiency of database SQLSQL explain (MySQL), enable slow query log to record slow queries. Usually also depends on the database design is reasonable, the demand is reasonable and so on.But this time is generally very fast, in less than a second, so you can not directly use mktime ()function Getmicrotime () {Lis
Hibernate native SQL query, Hibernate native SQL
Recently, a more complex query was made, and the basic query of hibernate could not meet the requirements. Therefore, we had to use the native SQL
I wrote a half-day SQL statement in the query analyzer and forgot to save it ~ What should I do if I want to retrieve an SQL statement that has been executed for a certain period of time?
I wrote a half-day SQL statement in the query analyzer and forgot to save it ~ What sho
Label:--Paging data----row_number () is called window-opening function, can be paged operation Select Row_number () over (order by ID) as Num,*from gb_data----adds a sequential num value to each column to facilitate the use of the first few data. Select row_number () over (order by ID) as num,* from Gb_data where Num>5and num 10--This line of code is wrong, because the system does not recognize how much num is, why? -Because of the order of execution, the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.