Q A location: http://space.cnblogs.com/q/20546/q A: I have asked more questions about the relationship: 5 [resolved issues] Browse: 52 times 00
Student table T1
Stu_id
Stu_name
1
Zhang San
2
Li Si
3
Wang Wu
Course list T2
Co_id
Co_name
1
Java
2
C #
3
C
4
C ++
5
Javascript
Link Table T3
Stu_id
Co_id
1
1
1
4
2
1
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
Label: CREATE VIEW View_1--Create a new view name as--functions for building viewsSelectStudent.sno,sname,cno,degree fromStudent join score on student.sno=Score.sno GoSelect* fromView_1wheresno='1'
Select* from
(SelectStudent.sno,sname,cno,degree fromStudent join score on STUDENT.SNO=SCORE.SNO) asTable2 wheresno='101'--define as a temporary table with AS and then query the results from the table.
is also a sub-qu
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)
Tags: style blog http color io ar for strong SPSQL query table, all field names of the table2011-07-29 10:21:43|Category: SQL Server | Tags: table sql fields | Report | Font size Subscription SQL query table, all field names of the tableSQL SERVERView all table nam
Tags: index solution based on keyword har results in SQL Server failure efficiencyProblem: There's a lot of data on both tables. The A1 field in a table needs to be associated with the B table primary key query A1 field stores multiple B table primary keys The format is: Format 1:B1,B2,B3 Format 2:B4 Format 3:b5,b6 Comma-delimited minority This leads to the use of like '%...% ', charindex, or replace (A1,B1
1, display line numberIf the data is not deleted, the primary key is consistent with the row number, but when some data is deleted, the row number is inconsistent with the primary key, and the need to query the line number requires a new method, and the temporary table is required before SQL Server2005, but in SQL Server2005, using the Row_ Number () is very conv
achievement of the same students with different course grades.43. Check the top two of the best results for each door44. The number of students enrolled in each course (more than 10 participants are counted). Require the output of the course number and the number of elective, query results in descending order of numbers, query results in descending order of numbers, if the number is the same, in ascending
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
Label:Today, I ran into a problem with a Sybase database query. A simple SQL, but do not know why the query does not come out, resulting in the production of the production server frequently hang out. Scared my little heart to bang. Select as Fcilcde from dnd_event_log A WHERE a.doc_ref =? and A.doc_type =? ' S ' Later, the network Operations Manager, the
Original: SQL Server 2012:SQL Server architecture--The life cycle of a query (part 2nd)Planning cache (Plan caches)If SQL Server has found a good way to execute a piece of code, it should be reused as a subsequent request because Generating execution plans is time-consuming and resource-intensive, There is a point in d
scroll lock depends on the cursor concurrency option and the lock prompt in the SELECT statement of the cursor. Optimistic read-only value
* Specifying the nolock prompt will make the table with the specified prompt read-only in the cursor.
16. Use profiler to track the query, obtain the time required for the query, and locate 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
IntroductionSee a popular blog today. NET Senior Engineer face questions of SQL, asked to find the highest score of each department, and by the department number, the student number in ascending order. This query is more complex, but also more typical, since the use of ORM, a long time did not write SQL statements, so I studied the next, I also wrote a: With Cte1
Method 1:When the publisher filter condition is NULL, how do you write SQL?1 DECLARE @publishers VARCHAR (50);2 SELECT * FROM dbo. Book WHERE Publishers=isnull (@publishers, publishers)Method 2:DECLARE @cinv varchar (50)SELECT * from inventory where 1=1 and ([email protected] or @cinv is null)Method 3:DECLARE @name VARCHAR (+), @page INT =1SET @name = ' Zhang San 'DECLARE @sql VARCHAR (1000)SET @
Enable AD Hoc distributed Queries: ' Show advanced Options ', 1
Reconfigure
' Ad Hoc distributed Queries ', 1
Reconfigure
When you are finished using, close ad Hoc distributed Queries:' Ad Hoc distributed Queries ', 0
Reconfigure
' Show advanced Options ', 0
Reconfigure
Operation:
' SQLOLEDB ' ' SQL Server name ' ' User name ' ' Password '
' SQLOLEDB ' ' SQL Server name ' ' User name ' ' Passw
,-1, GETDATE ()),111)//111 is the style number, (100-114)Query first day of the month Date: Select DATEADD (mm, DATEDIFF (mm,0, GETDATE ()),0) asfirstday Query Last day of the month Date: Select DateAdd (MS,-3, DATEADD (mm, DATEDIFF (M,0, GETDATE ()) +1,0)) asLastday//change-The value of 3 changes accordinglyHow many days are there this month:SelectDatePart (Dd,dateadd (dd,-1, DateAdd (MM,1, Cast ((CAST (GE
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.