Discover how to update multiple rows in sql, include the articles, news, trends, analysis and practical advice about how to update multiple rows in sql on alibabacloud.com
PL/SQL USE INSERT... to INSERT multiple rows in a SELECT statement, we usually use the INSERT command to INSERT rows into a table. Sometimes, you need to add specific data to the target table based on the records of existing tables and views, you can use INSERT... SELECT statement. The statement actually contains two p
Project requirements: Multiple rows of data in a table are displayed in a single field, as follows:For example, there are field id,name in Table A,There are field id,pid,des in table B,Table A, the data in table B are as follows:ID NAME1 sheets of three2 John DoeID PID DES11 languages21 Mathematics31 Foreign languages42 History52 geographyFinally I want to show the effect as:ID NAME KC1 three languages, mat
If you encounter a requirement in the project, you need to merge multiple rows into one row.
The table structure is as follows:
Name null type
--------------------------------------
N_sec_code not null char (6)
C_researcher_code not null varchar2 (20)
This table stores the ing data between "stock" and "researcher". Generally, for the same stock, there may be multiple
Problem Description:Neither in SQL 2000, nor in SQL 2005, does the aggregate function of the string be provided,Therefore, when we are dealing with the following requirements, it will be more troublesome:There are table TB, as follows:ID value----- ------1 AA1 BB2 AAA2 BBB2 CCCNeed to get results:ID values------ -----------1 AA,BB2 AAA,BBB,CCCThat is, the group by ID, the sum of the value (string addition)1
U.userid=ur. User_ID left joins Base_roleinfor R on R.role_id=ur. role_id) t where t.userid=t1. USERID for XML Path (")) as RoleName from (select R.role_name,u.userid,u.username,u.truename from base_userinfor u left Joi n base_userrole ur on u.userid=ur. User_ID left joins Base_roleinfor R on R.role_id=ur. role_id) T1 GROUP by Userid,truename,usernameLook at the results of the query, not what we want.It is important to pay attention to the following statements in the group by, although we writ
Tags: img different val sql2005 blog int section bar GESRequirements: By grouping, the contents of multiple records are combined into one, the effect is as follows: Database Example: CREATE TABLE [T2] ([NID] [bigint] null,[district] [nvarchar] (255) null,[town] [nvarchar] (255) NULL);
INSERT into T2 values (1, ' Huai area ', ' Cao Lao Ji Zhen ');
INSERT into T2 values (2, ' Huai District ', ' Huaibin Street ');
INSERT into T2 values (3, ' Huai Distr
To convert a result set to a column, use the window function and the case clause. to convert a result set to one or more rows, use the case clause and Cartesian product.
As shown in
Figure 1 Table A figure 2 Table B Figure 3
Question: How to obtain the result set shown in Figure 3 based on table A and table B? First, evaluate the Cartesian product of table A and Table B, as shown below:
With newtable(Select * from(Select * From) B as tabl
Concatenate multiple rows of records in the same column in Oracle into a string [SQL] -- raw data -- a 111 -- B 222 -- a 333 -- a 444 -- B 555 -- final result -- a 111*333*444 SELECT L4.L _ TIME, MAX (SUBSTR (L4. group CONTENT, 2) final field value FROM (SELECT L3.L _ TIME, SYS_CONNECT_BY_PATH (L3.L _ CONTENT ,'*') AS group content from (SELECT L2.L _ TIME, L2.L
Tags: sql, I'm going to add the Pre_tel column with 010 or another area code, but how do I use the same SQL statement?650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M02/93/F3/wKiom1kLIQWjsai3AABhAtHi4Pw818.png-wh_500x0-wm_ 3-wmp_4-s_3926489974.png "style=" Float:none; "title=" 2.png "alt=" Wkiom1kliqwjsai3aabhathi4pw818.png-wh_50 "/>650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/93/F3/
Oracle SQL converts a varchar type data into multiple rows of Results records. Today, when I create a report, I want to use an SQL query to query the final results. However, I encountered some problems during implementation, one field I found is varchar type, and a combination of m
and from this table column: Keywords through a derived table connection to uf_splitstringtotable (filehistory.keywords). The specific code is as follows: SELECTt1.[Id], T1.[Keywords], T1.[FileName], T1.[fileextension], T1.[Createduser], T1.[Createdtime], T1.[Importtype], i.item as keyword fromfilehistory T1OUTERAPPLY uf_splitstringtotable (t1. Keywords,',') I After the code executes successfully, the following results are returned: In this way, we can finish the results we need. 2015,fighting
Method for merging multiple rows of records in SQL:-- 1. Create a table and add Test Data Create table tb (id int, [value] varchar (10 ))INSERT tb SELECT 1, 'A'Union all select 1, 'bb'Union all select 2, 'aaa'Union all select 2, 'bbb'Union all select 2, 'ccc'-- SELECT * FROM tb/**//*Id value---------------------1 aa1 bb2 aaa2 bbb2 ccc(5 row (s) affected)*/-- 2 in
The results of the query before processing are as follows:By using the definition of SQL variablesDECLARE @Scope varchar( +)DECLARE @Num int SET @Scope="'SET @Num = 1 SELECT @Scope=@Scope+Convert(varchar(8),@Num)+','+Descscope+Descoper+';',@Num = @Num+1 fromFuel_contractqualitynewWhereContractid='012009000100'SELECTContractid,@Scope fromFuel_contractqualitynewWhereContractid='012009000100' GROUP byContractidAchieve the effect: //Create a funct
from dbo. Split (@WLCInvestorApplyID_Messge, ', ')Set @[email Protected][email protected] @error Insert INTO ModifyWkContent2 select Oldcashaccountno,newcashaccountno,t2.name,results1,results2,results3,results4, Results5,results6,results7,stateFrom #t2 T2, #t t1Set @[email Protected][email protected] @error Update modifywkcontent set state=1 where ID in (select ID from #t)Set @[email Protected][email protected] @error IF (select COUNT (*) from modify
Label:Ideas: Self-connect, using the for XML Path (") and stuff functions SELECT * from STUDENT Name Team------------------------- -------------------------Jack Team1Rose Team1Cindy Team1Richard Team2Jenny Team2 SELECTT1. Team,STUFF((
SELECTCONCAT ('/', T2. Name) fromSTUDENT T2WHERET2. Team=T1. Team forXML PATH ("')
),1,1,"')
asNAMES fromSTUDENT T1GROUP byT1. Team Team NAMES------------------------- ---------------------------------------------------------
Label:Inserting data into a table using the Insert SELECT -- Add the data inserted in T1 to T2 (the T2 table must exist, and the order, data type must be consistent with T1)
INSERT into T2 (Username,password)
SELECT from T1
Use SELECT into to add data from an existing table to a new table -- Add the data that is queried in T1 to T2 (the T2 table cannot exist.) will be created in execution)
SELECT t1_username, T1_password
into from T1 To insert an identity column: -- when
The number of rows that can be affected directly by the following methods:
Dim conn
Dim sql
Dim lngrecs
sql= "UPDATE table1 set field1= ' good '"
Set Conn=server.createobject ("Adodb.connection")
Conn.Open DSN
Conn.execute Sql,lngrecs
Conn.close:set conn=nothing
Respon
The first two days saw a blog post about how to convert a row of data that contains a single column of multiple values into a multi-row column in Oracle, with the following issues.ID number1 137xxxx,138xxxxTake it out.ID number1 137xxxx1 138xxxxThe solution given in the original text can be found in http://www.cnblogs.com/myjoan/p/4139348.html, and the reply seems to give a more concise wording.Because for several years did not touch Oracle, in recent
Label: DECLARE @num1 INT--The total number of rows that meet the criteria Select @num1 =count (1) from Cardinfo where opendate between @date1 and @date2 [email protected] and @date2 for the start time to the end time, you can understand a condition while (@num1 BeginPrint @num1-The value of the loop output @num1, minus oneSet @num1-=1Select top 1 @uid = CardID from cardinfo where CardID [email protected] is the card number of the table, using paginat
Tags: data usage exp Data character rom specify CTE insertSample table TB data is as follows ID value—————1 AA1 BB2 AAA2 BBB2 CCC SELECT ID,[Val] = (SELECT [value] + ', 'From TB as BWHERE b.id = a.id for XML PATH ("))From TB as a Show results1 AA,BB,1 AA,BB,2 AAA,BBB,CCC,2 AAA,BBB,CCC,2 AAA,BBB,CCC, SELECT ID,[Val]= (SELECT [value] + ', 'From TB as BWHERE b.id = a.idFor XML PATH (")")From TB as aGROUP by IDShow results1 AA,BB,2 AAA,BBB,CCC, SELECT ID,[Val]=stuff (SELECT ', ' +[value ')From TB a
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.