Case
It may be one of the keywords most misused in SQL. Although you may have used this keyword before to create a field, it also has more features. For example, you can
Where
Clause
Case
.First, let's take a look.
Case
. In normal
Select
The syntax is as follows:
Select
Mycolumnspec
>
toilet, be sure to obtain a complete lock, close the door to let others come in, otherwise if the other people came in, although he did not occupy the seat, but he took the toilet paper. You occupy the seat but no toilet paper, he took the toilet paper but no seat, the two sides do not give, who can not complete the toilet affairs, stalemate, and lead to deadlock. At this point you need to come to the toilet management, or force you to let go of the seat, do not manage you wipe your butt, or gr
Server
-----------------------------------------------------------------------------------------------
Author: Ongyan
Welcome to reprint, please retain this statement information.
Welcome to contact me, enhydra_boy@tom.com.
----------------------------------------------------------------------------------------------
Recently, in the CSDN forum, before and after answering the question of two friends, feel the need to sum up.
The problem is this.
The table game_info is known as follows
Date_info
Result_info
2018-2-4
Win
2018-2-4
Lose
2018-2-4
Win
2018-2-4
Lose
2018-2-5
Lose
2018-2-5
Lose
2018-2-5
Lose
Q. How do I find the following results?
Date_info
Win
Lose
2018-2-4
2
2
2018-2-5
0
3
Because the local database is not set to partition size during installation, but the server is a partition, I re-wrote some code, in order not to let this happen, I decided to change the local database to support the size of the region.
The Code is as follows:
Alter database databasenameCollate chinese_taiwan_stroke_cs_as
CiCase Insensitive,CSSpecifies the case sensitivity.
If it is a simplified versi
1. IF ELSEcannot be used in select, only blocks, such as:IF ...BEGIN...ENDelse (note that there is no else if, to be implemented can only be judged in the following block)BEGIN...ENDReference: Https://msdn.microsoft.com/en-us/library/ms182587.aspx2. Case and then ELSE ENDCan be used in select, but include end endCase ...When ... Then ...ELSE ... (can be omitted)ENDReference: Https://msdn.microsoft.com/en-us/library/ms181765.aspxSQL
implement a query with a single statement. But that increases the consumption (two select parts), and the SQL statement is longer.Here is an example of using the case function to accomplish this function SELECT country,
sum (case if sex = ' 1 ' then
population ELSE 0 END), --Male population
SUM (case if sex = ' 2 ' T
When a database server (Microsoft SQL Server (SP2) (KB3171021)-12.0.5000.0 (X64) discovered that a job called Database Mail sent a message, sometimes the same message was sent two times, After detailed inspection, to exclude the business logic in the job, there is a problem in the case of duplicate sending mail, check
Tags: reference name col except contact Att sink ber walSQL Server Table Management _ Detailed information on the operation of data deletion and modification (case code)-DML 1. SQL INSERT INTO statement (insert in table) The INSERT INTO statement is used to insert a new record into the table. SQL INSERT into Syntax The
Case when usageSELECT L.lettertype, u.realname from T_lettersrecord as L, t_user as U WHERE (case when l.lettertype = ' Cadre Letter of introduction ' and U.userid = ' 1 ' THEN1 whenl.lettertype = ' Cadre Letter of introduction ' and u.userid Operation Result:3. Use of GROUP by caseSELECT Case wh
!))。 Restart the service, run a day, and then look at the Event Viewer, no longer found similar records, CPU utilization decreased to about 5, the system response significantly faster. The problem has been satisfactorily resolved.To prevent hackers from traversing the system login account. Administrator was renamed, but after renaming, SQL Server could not start. Found
Copy Code code as follows:
--Simple Case function
Case Sex
When ' 1 ' THEN ' male '
When ' 2 ' THEN ' woman '
Else ' other ' end
--case search function
case when sex = ' 1 ' THEN ' man '
When sex = ' 2 ' THEN ' female '
Else ' other ' end
In both of these ways, you can achieve the same
--Simple Case functionCase SexWhen ' 1 ' THEN ' male 'When ' 2 ' THEN ' woman 'Else ' other ' end--case search functioncase when sex = ' 1 ' THEN ' man 'When sex = ' 2 ' THEN ' female 'Else ' other ' end
In both of these ways, you can achieve the same functionality. The simple case function is relatively concise, but there are some limitations to the function, s
The case may be one of the most misused keywords in SQL. Although you may have used this keyword before to create a field, it has more usage. For example, you can use the case in the WHERE clause.
First let's take a look at the syntax of the case. In a general SELECT, the syntax is as follows:
SELECT CASEWHEN WHEN EL
Label:PIVOT syntax. SELECT [First pivot column] as [Second pivot column] as ... [Last Pivot column] as From ( Aliases for as PIVOT ( For [ In ([First pivot column], [Second pivot column], ... [last pivot column]) ) as SELECT * FROM StudentPivot (max (score) for project in ([Language],[Math],[Foreign Language]) as Pvt SQL Server row to column small case
--------------------------------------------------------------------------------------------------------------- -------------------1. File Header page:2. Page Free Space page:3. GAM:If the corresponding area is occupied corresponding to the bit is 0, if the area is not occupied corresponding to the bit is 1, each GAM can cover 4GB of data every 511 230 pages will have a GAM page.4, SGAM:If each page in the zone is occupied by the corresponding bit is 0, if the page is not occupied the correspond
Tags: des style class C a colorWhen you synchronize an Oracle table to SQL Server, you may experience this error when you apply data on the SQL Server side. 2014-05-17 17:20:24 WARNING OGG-01154 SQL error-2147217887 mapping Applsys. Fnd_flex_validation_rules to dbo. Fnd_flex
Due to the previous period of stomach pain, the blog Park blog has been stopped more than one months or so. In recent days, stomach trouble finally slightly improved, decided to re-write blog post.A few days ago, a friend just asked me about the SQL statement, roughly the original table has two columns, respectively, the month, the month sales, and the need for a SQL statement to achieve the statistics of e
Tags: style blog color strong file data problem divSQL Server service cannot start1) When you start the SQL Server (SQLEXPRESS) service, you are prompted with the following error:The local computer cannot start the SQL Server (SQLEXPRESS) serviceError 3: The system cannot fi
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.