Alibabacloud.com offers a wide variety of articles about compare two columns in sql, easily find your compare two columns in sql information here online.
Http://cheneyph.iteye.com/blog/477829
In Java, there are several methods to obtain the total number of rows of the resultset.
First, use the getrow method of the resultset to obtain the total number of rows of the resultset.
Statement stmt = con. createstatement (resultset. type_scroll_insensitive, resultset. concur_updatable );Resultset rset = stmt.exe cutequery ("select * From yourtablename ");Rset. Last ();Int rowcount = rset. getrow (); // obtain the total number of rows in the resu
First, I have a movie database. This is part of it: [rel] movie_id, star_id, and time are generally a movie, corresponding to multiple performers. The same movie_id and star_id can only appear once in the database. However, previous system design vulnerabilities lead to repeated insertion... first, I have a Movie Database, which is part of it:
[Rel] movie_id, star_id, time
Generally, it is a movie that corresponds to multiple performers. The same movie_id and star_id can only appear once in the
SQL: insert all other columns of rows with the same primary key updated.
In SQL writing, we often encounter such problems. During each insert operation, you must determine whether the data table already exists. For the same data, all the columns except the primary key are the same. If no data exists, the data is inser
= 2Set @ startpage = 1Set @ SQL = 'select top '+ STR (@ endpage-@ startpage + 1) + 'from DBO. Employees where RID not in (select top'+ STR (@ startPage-1) + 'rid from DBO. Employees where RID> 1 )'Exec sp_executesql @ SQL-- Range QuerySelect * From DBO. Employees where birthdate between '2017-01-01 'and getdate ()Select * From DBO. Employees where birthdate not between '2017-01-01 'and getdate ()-- Delete
Alter table: add, modify, and delete table columns, constraints, and other table definitions.
View column: DESC table name;
Alter table t_book Rename to BBB;
Add column: alter table table name Add column name varchar (30 );
Delete column: alter table Table Name drop column name;
Alter column name MYSQL: alter table bbb change nnnnn HH int;
Modify the column name sqlserver: exec sp_rename 't_ student. name', 'nn ', 'column ';
When I wrote this article, I referred to the book "SQL hacks", which uses SQL Server 2008.
For example, there is a table
create table tbCourseGrade(student varchar(10) , course varchar(10) , grade int )
Then there are some records:
Insert into tbcoursegrade (student, course, grade) values ('James ', 'high number', 98), ('James', 'English ', 56), ('James ', 'China', 77), ('small red', 'high data', 89)
Tags: http technology present tar comma Ace SEL Reference codeToday to change to the old man's code, actually put multiple IDs in a column, or use the comma partition ... What do you do when you inquire???Search the internet for half a day, finally found a SQL Server inside there is a parsename function, you can press. (dot) to split the string,So I wrote down the following SQLSELECT ParseName (REPLACE(fromagentids,',','). '),1 as one,parsename(REPLAC
value in the identity column, a No. 2627-number error message is generated later when the table is referenced. The current identity value can be greater than the maximum value in the table. In this case, DBCC checkident does not automatically reset the current identity value. To reset the current identity value when the current identity value is greater than the maximum value in the column, use either of the two methods: Execute DBCC CHECKIDENT (' table_name ', noreseed) to determine the curren
Tags: union ALL arch SQL Identity Har left join declare from nvarcharDeclare @table table (name nvarchar (4))INSERT INTO @tableSelect ' Zhang San ' union ALLSelect ' John Doe ' UNION ALLSelect ' Harry ' UNION AllSelect ' Liu San ' union ALLSelect ' Yang II ' union ALLSelect ' Hu Ba ' union ALLSelect ' Zhao Liu '--Method 1:CREATE table #t (ID int identity (), name nvarchar (4))Insert into #t (name) SELECT * FROM @tableSelect A.name,b.name from #t a LEF
SQL Max can be used to calculate numeric or character columns.
However, you must pay attention to the special case of Max character columns.
For example, if the key column is a character column, there are currently 1, 2, 3, 4, 5... 9 Data
Now add 1 to the front to get the next key value.
The general method is as follows:Declare @ next_key int
Select @ ne
Existing table table1, four int field f1,f2,f3,f4, now query to get the maximum value in the four column and only need to return the maximum value
Method One:
Select Case if F12>f34 then F12 else F34 end as Maxnum to
(Select Case when F1>f2 then F1 else F2 end as F12 , case when
F3>f4 then F3 else F4 end as F34 to table1) as T1 ORDER BY maxnum Desc
The effect is as follows:
Method Two:
Select top 1 * "from" (
select F1 as Maxnum, ' F1 ' as ColumnName from TABLE1
UNION
SELECT F2
Delete data columnsThe data columns that are built, wrong, or duplicated in the development or production process need to be deleted.Use the SSMS database management tool to delete data column mode one1. Open database--Select data Table-"Expand Data Sheet-" Expand Data Column-"Select the data column to delete-" Right click-"SELECT Delete-" in the Pop-up box click OK.Way Two1. Open Database-"Open data Sheet-" Right click-"SELECT Design.2, in the Design
Label:The columns of table two are updated to table one (same library, cross-Library), and the A and B tables are associated by field Empid. Requires that updates between the associated records need to be one by one corresponding to the relationship. The statements are as follows:Update Set = from where = Table Two. EMPIDTo actually apply the SQL statement:Update Crm.dbo.Crm_Project Set CRM: Crm_project.pr
--through Max ... Case ... When ... Converting column dataSelectStudent as 'name',MAX( CaseSubject when 'language' ThenScoreELSE 0 END) as 'language',--Replace subject column data with score column dataMAX( CaseSubject when 'English' ThenScoreELSE 0 END) as 'English' --Replace subject column data with score column data fromScoresGroup byStudentOrder byStudentSELECTStudent as 'name', --Converting a language column with the AVG function AVGLanguage as 'language', --convert English
For example, the results of an SQL query in PL/SQL are as follows:
Leaf
Wei
Hong
Sun
He
... Is omitted later
To generate the dictionary format:
{1, "Ye" },{ 2, "wei" },{ 3, "Hong" },{ 4, "Sun" },{ 5, "He "}...
First, copy the columns of PL/SQL, put them in a string, and cycle the char of this string. Because t
Tags: Map SQL Server operator arithmetic rules overlap List section allowsPartitioning column RulesThe partitioning column exists on each member table and identifies the available data in a particular table through a CHECK constraint. The partitioning column must adhere to the following rules:Each base table has a partition column that has key values enforced by the CHECK constraint. The key range of the CHECK constraint for each table does not overla
Label:SQL converts one column in a row of data from a query to a column, as the result of the original lookup is: User_name Tom John doe Harry Now you want to merge it into: CUSTOMER Zhang San, John Doe, Harry The SQL statements are as follows: Select STUFF ((select ', ' +user_name from TBale where User_name = ' FOR XML path (') '), 1, 1, ') CUSTOMER Where stuff is a method function for SQL encapsulatio
The following two tables have the same structure. use SQL to find columns with different values.
Student_1
NAME
AGE
SCORE
Peter
26
100
Jack
25
96
Daniel
26
48
Bark
21
69
Student_2
NAME
AGE
SCORE
Peter
26
89
Jack
25
96
Daniel
26
48
Bark
21
69
Met
Calculate the sum of order quantities
$query_num"SELECT SUM(order_num) from hcf_order_db where order_id = XXX";$arr_qn = mysqli_query($dbc,$query_num);list($sum)=mysqli_fetch_row($arr_qn);
Calculate the sum of the order Amount
$query_amount"SELECT SUM(order_amount) from hcf_order_db where order_id = XXX";$arr_qm = mysqli_query($dbc,$query_amount);list($sum2)=mysqli_fetch_row($arr_qm);
Then there is the PHP output:
tdclass='font-songti'align='center'>
echo$sum?>
td>tdclass='f
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.