Click here if you want to view the original text.
So I made a small modification to the SQL statement to achieve my goal. In my test, the table name is ctest, and the field name is pinyin.
This is before sorting:
The SQL statement used is as follows:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->Update ctest
Set mingci = (
Select count (*) + 1
From
ages and: Select sum (sage) from student;Check the average age of all students:select AVG (SAGE) from student;Check the age of the oldest student : select Max (sage) from student;Check the age of the youngest student : select min (sage) from student;Statistics of Secondary Students:select COUNT (sname) from student;9. Group queriesYou can display the results of a query in groups according to a certain condition.Keyword:broup byGroup students according to gender :Selete * FROM student group by s
[Zhuantang learning notes] basic SQL query statements (single-Table query and multi-Table query)SQLQueryBasic1. Single Table query
It is also called projection.
Basic query statement Structure
Select column from table
* Not all other columns
Query all data
Example: SELECT * FROM t_studen
Perform a relatively fine operation and add conditional Filtering: Query stu
Environment: SQL Server 2008 R2
Question: The annotation usage in SQL Server is not clear.
Solve:
Single-line Comment:--
Multi-line Comment:/*......*/
Use examples:
Single-line Comment:
-The column ' Student.sname ' in the select list is
not valid because the column is not included in an aggregate function or
Query the SQL statement that all databases consume disk space size:SelectTable_schema, Concat (truncate(sum(data_length)/1024x768/1024x768,2),'MB') asData_size,concat (truncate(sum(index_length)/1024x768/1024x768,2),'MB') asindex_size fromInformation_schema.tablesGroup byTable_schemaOrder byData_lengthdesc;SQL statements that query the size of all table disks in a sin
In SQL databases, it is often difficult to figure out whether to write single quotes or double quotes when writing some statements. After some queries, I agree with the following. Here, the string type is used as an example:
When I have a table named studentname, there is a field named
I want to insert a name named "Zhang San" into it, so
Strtxtsql = "insert into studentname (name) value ('zhang san ')
duplicate records (duplicate records retain 1),You can delete it as followsSELECT DISTINCT * to #Tmp from Tablenamedrop table Tablenameselect * to tableName from #Tmpdrop table #TmpThis duplication occurs because the table is poorly designed and the unique index columns are added to resolve.2. This type of repetition usually requires the first record in the duplicate record to be retained, as follows, assuming that there is a duplicate field name,address, which requires a result set that is uni
fromTablenamedropTableTablenameselect* intoTableName from#TmpdropTable#Tmp This duplication occurs because the table is poorly designed, and the unique index column is added to resolve. 2, this type of repetition usually requires the first record in the duplicate record to be retained, as follows, assuming that there is a duplicate field name,address, which requires a result set that is unique to both fields selectIdentity(int,1,1) asAutoid,* into#Tmp fromTablenameselectmin(autoid) asAutoid i
Example: strsql = "selcet * From sp_table where XM = '" text1.text "'"
It may be difficult to use and connect strings. "" is a string, "" and "" are connected with and
Assume that the value of text1.text is Li Si.
Then it should be written:
Strsql = "select * From sp_where sp_table where XM = '" "'"
Now it is divided into three parts:
"Select * From sp_table where XM = '"
Li Si
"'"
Change Li Si to text1.text
Simply put, double quotation marks are used for VB and
Tags: nbsp statement table Insert Field sel ble from tabSELECT * into new table name from (SELECT * FROM T1 UNION ALL SELECT * from T2) This statement can be implemented to append the merged data to a new table. Do not merge duplicate data SELECT * FROM T1 UNION ALL SELECT * FROM T2 Merge duplicate Data SELECT * FROM T1 Union SELECT * FROM T2 Two tables, table 1 table 2 If you want to incorporate table 1 data into table 2, use the following statement Insert INTO Table 2 (Field 1, Field 2) Selec
Label:Select
a.name as constraint name,
object_name (b.parent_object_id) as foreign key table,
D.name as foreign key column,
object_name ( b.referenced_object_id) as Master, c.name as
primary key column from
Sys.foreign_keys A
inner JOIN Sys.foreign_key_columns B On a.object_id=b.constraint_object_id
INNER join sys.columns C on b.parent_object_id=c.object_id and B.parent_ column_id=c.column_id
INNER JOIN sys.columns D on b.referenced_object_id=d.object_id and b.referenced_column_id= d.column_id
SQL injection without single quotes or commas
0X00 background
Audit cms found an environment like this:
$ L_id = get ('arr', 'l _ id'); $ ids = explode (',', $ l_id );
Concatenate the array requests in post, and then separate them with commas (,). Finally, an SQL query is provided.
As a result, you may not be able to use commas.
Default
Display_error = off
Query for SQL statements that all databases consume disk space size:
Copy Code code as follows:
Select Table_schema, concat (Truncate (SUM (data_length)/1024/1024,2), ' MB ') as Data_size,Concat (Truncate (SUM (index_length)/1024/1024,2), ' MB ') as Index_sizeFrom Information_schema.tablesGROUP BY Table_schemaORDER BY data_length Desc;
Query for SQL statements that are sized for all
Label: Tags: SQL merge data 2013-08-21 10:41 489 people read Comments (0) favorite reports Classification:Oracle Database (DB) SELECT *into new table nameFrom (SELECT * FROM T1 UNION ALL SELECT * from T2)This statement can be implemented to append the merged data to a new table.Do not merge duplicate dataSELECT * FROM T1 UNION ALL SELECT * FROM T2Merge duplicate dataSELECT * FROM T1 Union SELECT * FROM T2 Two tables, table 1 table 2If you want to
--The project needs to use the Merg grammar, so went online to check the data, found that it is a multi-table query, the problem is that I only have a table, so I am puzzled, and then I brainwave, it's done!--Table name: T_login (Login table)--field: F_username (username), f_status (login status 0 = logged in)--Execution requirements: When the user logs on, if the user is present, the modification status is 0, and if it does not exist, add a record--Define the parameters:DECLARE @f_userName varc
all the conditions are added to the front and back of the symbol and the signal, just to note that the last piece of the search, the last one will have a funny symbol
Remember to delete the tag and then paste it into SQL, otherwise the inquiry will fail!
(After completion, the windows of a duplicate macro will not be automatically closed, and you can cancel it)
10. The requirements have been achieved by completing the above steps, but if you turn
DISTINCT keywords to remove duplicate rows from the table. If no distinct keyword is specified, all is the defaultSELECT DISTINCT Sno from SC;Common Query conditions:
Query criteria
Predicate
Comparison
=,
Determine scope
Between and, not between and
Determining the Collection
In, not in
Character matching
Like, isn't like
Null value
Is null, was NOT NULL
Multiple con
--Create a data table that defines the structure of the stored Data information table--CREATE TABLE t_student (Name text, age integer, Phoneno text);--Deleting a data table is usually used when you don't need to use a table , which is rarely used in daily development--DROP TABLE t_student;--new data content, in SQL statements, strings need to be enclosed in single quotation marks--syntax format for INSERT s
When combining data across multiple tables, it is sometimes difficult to figure out which SQL syntax to use. Here I will describe how to merge queries from multiple tables into a single declaration.
In this articleArticleThe sample query meets the sql92 ISO standard. Not all database manufacturers follow this standard, and the improvement measures taken by many manufacturers may have unexpected consequenc
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.