functionremoverepetition (str) {varresult = "", Unstr; for(vari=0,len=str.length;i){ //because UNSTR is always the previous letter of the current Str.charat (i) because the assignment of Unstr Unstr=str.charat (i) is done in the previous cycle //so you can delete the place where it repeats. if(Str.charat (i)!==unstr) {Unstr=Str.charat (i); Result+=Unstr; Console.log (result); } } returnresu
Let's say we have a MongoDB collection,
Take this simple set as an example, we need to include how many different mobile phone numbers in the collection, the first thought is to use the DISTINCT keyword,
Db.tokencaller.distinct (' Caller '). length
If you want to see specific and different phone numbers, then you can omit the length property, since Db.tokencaller.distinct (' Caller ') returns an array of all the mobile phone numbers.
However, this approach is sufficient for all situations.
#Tmpdrop table #Tmp This duplication occurs because the table is poorly designed and the unique index columns are added to resolve. 2, this kind of repetition problem usually requires to keep the first record in the duplicate record, the operation method is as follows Suppose there is a duplicate field name,address, which requires the result set to be unique for both fieldsSelect Identity (int,1,1) as Autoid, * into #Tmp from TableNameSelect min (autoid) as autoid into #Tmp2 from #Tmp Group by
, build library and other languages)2.DML (Data Manipulation language mutipulation) Add delete modify and query also called cuid: Database additions and deletions 3.DCL (Database control Language)Type conversions1.--cast (source data as target type)--2.--convert (destination type, source data, format (date value format))Select GETDATE ()--Get current system time select GETDATE ()Union result set Union (rarely used)Union All: Shows whether the result is repeated or notUnion: Duplicate data is not
1, use distinct to weight (suitable for querying the total number of the whole table)There are multiple schools + teachers to contribute, need to count the total number of authorsSelectcount (author)As total from files each author has a lot of contributions, there are duplicate records here. Selectdistinctauthor from files;It is possible that the names of teachers in both schools are the same, and only one error is counted. SelectdistinctAuthor,sid the combined unique value of the From files sta
Tag: equals code uses element delete to perform dev repeat hashTo insert into the database go to weight: 1. Iterate through the list you have read 2. Get the data you need to query before you insert the method into the database, execute the Query method 1 devlist=devicedao.finddevice (Device.getrfid ());
2 if (Devlist.size () >0) {
3 messagestr = "Duplicate data, please re-import!" ";
4
5 } Else {
6 devicedao.save (device);
the repetition at that time.The approximate process is as follows:(1), select one record with the largest ID in each duplicateCreate Table as (selectmaxfromgroupby havecount(*) > 1)(2), create INDEX (only need to execute at first time)Alter Table Add index name (field name)(3), delete the record with the largest ID in duplicatesDelete from where inch (Select from Tmp_relation_id2)(4), delete temporary tableDrop Table Tmp_relation_id2Repeat the steps above (1), (2), (3), (4) until the record
onSql>flashback database to SCN Scnno;Sql>flashback database to timestamp to_timestamp (' 2007-2-12 12:00:00 ', ' yyyy-mm-dd hh24:mi:ss ');Summarize:Oracle provides these mechanisms to ensure safe operation, but at the same time comes another problem, is the space occupancy, due to the operation of the above mechanism, using the drop of a table or delete data, the space will not be self-Recycle, for some of the tables that are determined not to be used, when removing the space at the same time,
Today, my friend asked a particularly tangled question: in a database table, we need to repeat a field in the table and sort the remaining data by another field,
Today, my friend asked a particularly tangled question: in a database table, we need to repeat a field in the table and sort the remaining data by another field,
Today, my friend asked a particularly tangled question:
In a table in the database, the table duplicates a field in the table and sorts the remaining data according to ano
having count (*)> 1Change the ">" number above to "=" to query the non-duplicated data.For exampleCopy codeThe Code is as follows:Select count (*) from (select gcmc, gkrq, count (*) from gczbxx_zhao t group by gcmc, gkrq havingCount (*)> = 1 order by GKRQ)Select * from gczbxx_zhao where viewid in (select max (viewid) from gczbxx_zhao groupGcmc) order by gkrq desc --- this is feasible..One question says: the efficiency of distinct deduplication is ver
The group by statement can deduplicate a column.Directly run the preceding statement: select io_dev_id from io_info where (TID = 1 AND host_name = 'yang1') group by 1; deduplication BY io_dev_id. P: The difference between order by and distinct is that group by is used to select order by Based on the column. distinct is similar to group by, but it can only be placed behind select, the front of the filtered field. For example, select distinct a, B, c fr
Today, my friend asked a particularly tangled question:
In a table in the database, the table duplicates a field in the table and sorts the remaining data according to another field,
Create a table as follows:
Create table TEST_DISTINCT (ID integer not null,NAME varchar (20) not null);
Insert into TEST_DISTINCT values (0, 'A ');Insert into TEST_DISTINCT values (1, 'bb ');Insert into TEST_DISTINCT values (2, 'cc ');Insert into TEST_DISTINCT values (3, 'dd ');Insert into TEST_DISTINCT values (4, '
field 1, Field 2 having count (*)> 1
Change the ">" number above to "=" to query the non-duplicated data.
For example, select count (*) from (select gcmc, gkrq, count (*) from gczbxx_zhao t group by gcmc, gkrq having
Count (*)> = 1 order by GKRQ)
Select * from gczbxx_zhao where viewid in (select max (viewid) from gczbxx_zhao group
Gcmc) order by gkrq desc --- this is feasible.
One question says: the efficiency of distinct deduplication is very low. I
Php 3D array deduplication (sample code ). Suppose it is called array $ my_array; copy the code as follows: create an empty array. $ tmp_arrayarray (); $ new_arrayarray (); 1. loop all rows. ($ val is a row) suppose it is an array $ my_array;
The code is as follows:
// Create an empty array.$ Tmp_array = array ();
$ New_array = array ();
// 1. loop all rows. ($ val is a row)Foreach ($ my_array as $ k => $ val ){
$ Hash = md5 (json_encode ($ va
!!"); } } }This will only intercept up to 50 joke messages to avoid slow read and write problems caused by large data volumes.The function where the bean is converted to a JSON string is as follows// Bean conversion JSON Public Static String Beanconverttojson (Object obj) { new Gson (); = Gson.tojson (obj); LOG.D ("Utilshelper", "JSON =" + json); return json; }Don't forget to add permissions for SDcard operations and file read and write in
The array_unique () function of PHP allows you to pass an array, remove duplicate values, and return an array with unique values, this article describes how to implement PHP array de-duplication quickly. For more information, see this article.
The array_unique () function of PHP allows you to pass an array, remove duplicate values, and return an array with unique values. This function works well in most cases. However, if you try to use the array_unique () function in a large array, it will ru
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.