1. Preface recently, due to project requirements, the employee's working group needs to be returned to the front-end, but the database stores the employee's working group Id in a field (with ldquo; comma
1. Preface recently, due to project requirements, the employee's working group needs to be returned to the front-end, but the database stores the employee's working group Id in a field (with ldquo; comma
1. Preface
Recently, due to project requirements, the employee's working group needs to
When you manipulate a database, you often encounter an updated or deleted row value that either does not make the row a unique row or changes multiple rows, as follows:
Reason analysis: Prompt that the deleted row is not the only row, and then check it again and discover:
is a duplicate key value or data that appears in the database, prompting an error when you try to delete
In Oracle, the dataset is merged (multiple rows and one row), and the relationship between table A and table B is one-to-many. Query all the data in Table A and merge A project in Table B corresponding to Table A into one row,
In Oracle, the dataset is merged (multiple rows and one row), and the relationship between t
=" 0 "alt=" 3941002.png "/>The second step is to write a view, using wmsys.wm_concat () to merge the KC_CJ fieldSQL code:Createorreplaceviewview_ly_sjdxpt_jwcj_kz asselect Hm,wmsys.wm_concat (KC_CJ) as KCCJ from VIEW_LY_SJDXPT_JWCJ groupby HmResults:650) this.width=650; "src=" http://img.dnbcw.info/2012413/3941003.png "border=" 0 "alt=" 3941003.png "/>The third step is to use it in the SQL you actually need:SQL code:SELECT DISTINCT' Academic performan
After the oracle splits the string, it is displayed in a single column and multiple rows.
Original SQL:
Select substr (field1, instr (field1, '|', 1, rownum) + 1, instr (field1, '|', 1, rownum + 1)-instr (field1, '|', 1, rownum)-1) as field2 from (select '| 'a | bbb | cccc | ddddd | ee | d | a' |' as field1 from dual) connect by instr (field1, '|', 2, rownum)>
Copied from http://www.mssqltips.com/sqlservertip/1771/splitting-delimited-strings-using-xml-in-sql-server/DECLARE @t TABLE(IDINT IDENTITY, the dataVARCHAR( -) )INSERT into @t(data)SELECT 'Aa,ab,ac,ad'INSERT into @t(data)SELECT 'BA,BB,BC'SELECT * from @tSELECTID, data, D.r.value ('.','nvarchar ()') DD from ( SELECTID, data,CAST('' + REPLACE(Data,',','')+ '' asXML) XMLData from @t) A CrossAPPLY A.xmldata.nodes ('Data') asD (R)Split strings and
When I tried a table, I added several pieces of data to it. Later I found that the values of the fields originally intended as primary keys are "null". This is not acceptable. Delete the fields and try again. When you select Delete, the following error occurs: "The modified or deleted row value cannot be changed to a unique row, or multiple rows (x rows) have bee
This problem was encountered today when resolving a problem, ORA-01427: Single row subqueries return multiple rows
It was later discovered that the SQL statement returned multiple results in the subquery.
Sub-query:
Select DISTINCT Cus_goodsno from V_biz_goods_match Dwhere D.sup_goodsno = i.goodsid and D.flag = 0 an
In MySQL There are keyword group_concat that provide similar functionality, and similar feature keywords in Oracle are wm_concat. For example, I have the following query data:But I would like to be able to display a row of queries, the result graph is as follows:Key SQL code shapes such as:select t.sglcheckid,wm_concat(t.salemodulename) from t_item_group_ex t where t.sglcheckid = ‘000********004‘ group by t.sglcheckidMySQL multi-line merge into one li
"style=" margin:0px;padding:0px;border:0px; "/>3, the reason that you can use Alias in the column Alias,order by clause is that SQL Server engine executes the SELECT clause before executing the ORDER BY clause.Select ID as orderid,code,name from
dbo.dt_test dt with (NOLOCK) Order by OrderID650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/628084/201510/628084-20151015182512757-836194158. JPG "style=" margin:0px;padding:0px;border:0px; "/
Label:Requirements Description: Table A has the following data
Id
1
2
3
4
Table B has the following data
Id
Name
1
Aaa
1
Bbb
1
Ccc
2
Aa
2
Bb
3
C
A and B tables are associated by ID and require the following query results:
Id
Name
Row Operations of SQL statements: rows of SQL statements
SQL statements are explained in the following articles:
1. SQL statement Row Operations
2. SQL statement-based table operations
3. Database Operations for
SQL Update multi-table joint Update method, sqlupdate joint Update
Sometimes we need to update the data in multiple tables at the same time, then we need to use the following method:
(1) sqlite multi-Table
MyBatis is recognized and used by everyone because of its simplicity and ease of use.
But in the batch update operation, the online introduction of seemingly incomplete, just do a record today, we progress together
In the actual project development process, there is often such a requirement: According to the IDs update the table of a field value, the SQL statemen
One: Executes the SQL statement, returning the number of rows affected In MySQL, if there is no effect, then the number of rows returned is-1, SQL Server has not been tested Usingnew Mydbcontext ()) { ctx. Database.executesqlcommand ("UPDATE person SET Name = ' Michael '
mode, the corresponding T-SQL code is as follows: EXEC dbo. usp_GetInsertSQL @ chvnTable = n'userlogininfo', -- nvarchar () @ chvnWhere = n', -- nvarchar () @ bitIsSingleRow =; -- bit GO
The query result after execution is as follows:
Then test the multi-line mode effect, the corresponding T-SQL code is as follows:
EXEC dbo.usp_GetInsertSQL @chvnTable = N'UserLoginInfo', -- nvarchar() @chvnWhere = N'
In SQL Server 2005/2008/2008 R2, we can use the first 200 lines of SQL Server editing function. The purpose of this function is to simplify the use of update, let developers, DBAs and people who do not know T-SQL can directly modify the data in the database through the visual interface. When editing the first 200
30 women 7902 FORD ANALYST 7566 1981/12/3 3000.00 20 female 7934 MILLER Clerk 7782 1982/1/23 1300.00 10 male Rows selected
Second, row and column conversion methodRequirements: Check the total salary for different positions in each department.1, the most traditional SQL solution is as follows:
Sql> Select D.dname, E.job, sum (SAL
Each time you import an Excel table to the database, several more rows are displayed as 'null' rows. The following prompt is displayed when you delete the table.
"The key column information is insufficient or incorrect. Update affects multiple rows! "
Solution: You can see
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.