skip

MySQL Group By And Skip Grouping On Null Values

不羁岁月 提交于 2019-12-04 06:04:49
select * from dc_deal group by collection_id In collection_id column i have values (1,3,3,4,4,5,NULL,NULL) . Above query will return rows with (1,2,3,4,NULL) but i want to skip grouping on NULL value and need result like (1,2,3,4,NULL,NULL) If we have a unique column (or set of columns) in the table, then we can add another expression to the GROUP BY . The expression needs to return a unique value for each row when collection_id is null. Otherwise, it returns a constant. Assuming we have a unique id column in the table, then we can do something like this: ... GROUP BY collection_id, IF

TODO:从数据库中随机抽取一条记录

二次信任 提交于 2019-12-03 14:46:13
TODO:从数据库中随机抽取一条记录 1.最直接,最粗暴的方法先计算记录的总数,然后选择一个从0到记录总数之间的随机数n,利用skip跳过n条记录,这是效率低下的的方法,首先的记录总数,在用skip会很耗时间; 2.那么有什么办法能够提供效率呢,方法就是给每条记录添加一个0-1的随机因子random。 “random” : 0.5127909016609585 想要在记录中查找一个随机记录,只要计算出一个随机数并作为查询条件就好了 Result = db.getCollection(‘qq’).findOne({“random”:{“$gt”:random}}) 如果出现查询不到数据,那是因为随机数比记录中存的随机值都要大,就没有结果返回了,那就换个方向查询了,就可以查询到想要的数据了 Result = db.getCollection(‘qq’).findOne({“random”:{“$lt”:random}}); 3.更多复杂的查询,可以把随机因子包含在索引里面。 这样,随机获取一条记录,我们也可以随机获取n条记录,做相应的业务环境使用 wxgzh:ludong86 来源: oschina 链接: https://my.oschina.net/u/2964302/blog/793911

Is it possible to only test specific functions with doctest in a module?

ε祈祈猫儿з 提交于 2019-12-03 10:35:39
I am trying to get into testing in Python using the doctest module. At the moment I do Write the tests for the functions. implement the functions code. If Tests pass, write more tests and more code. When the function is done move on to the next function to implement. So after 3 or 4 (independent) functions in the same module with many tests I get a huge output by doctest. And it is a little annoysing. Is there a way to tell doctest "don't test functions a() , b() and c() ", so that it runs only the unmarked functions? I only found the doctest.SKIP flag, which is not sufficient for my needs. I

removing doctype while saving domdocument

杀马特。学长 韩版系。学妹 提交于 2019-12-03 10:31:14
I am parsing and fetching html documents to DOMDocument. Those documents are child forms that will be displayed inside another page. While saving parsed DOMDocuments, it automatically adds doctype, html, head and body tags. since i am working on child forms i would like to remove all those and save only the child tags of form. How can i skip automatic generation of html, head, body and other tags while saving domdocument? Same as @KoolKabin answer, but a little shorter: return preg_replace('~<(?:!DOCTYPE|/?(?:html|body))[^>]*>\s*~i', '', $dom->saveHTML()); Got it myself after reading through

In Perl, how to “jump over” certain text and do search-and-replace in the remaining part? [duplicate]

本秂侑毒 提交于 2019-12-02 23:20:50
问题 This question already has answers here : How to perform search-and-replace within given $start-$end ranges? (4 answers) Closed 3 years ago . The text has many occurrences of pattern ; while doing regex find-and-replace, I wanna jump over certain segments of the text, and replace pattern in the remaining part. Example, in the code: #!/usr/bin/env perl use strict; use warnings; #iterate the DATA filehandle while (<DATA>) { # This one replaces ALL occurrences of pattern. s/old/new/gs; # How do I

java foreach skip first iteration

旧城冷巷雨未停 提交于 2019-12-02 18:42:18
Is there an elegant way to skip the first iteration in a Java5 foreach loop ? Example pseudo-code: for ( Car car : cars ) { //skip if first, do work for rest . . } Sean Adkinson I wouldn't call it elegant, but perhaps better than using a "first" boolean: for ( Car car : cars.subList( 1, cars.size() ) ) { . . } Other than that, probably no elegant method. With new Java 8 Stream API it actually becomes very elegant. Just use skip() method: cars.stream().skip(1) // and then operations on remaining cars yop83 Use Guava Iterables.skip() . Something like: for ( Car car : Iterables.skip(cars, 1) ) {

Java AudioInputStream how to support skip with negative number of bytes

陌路散爱 提交于 2019-12-02 13:46:38
问题 I am trying to skip a negative number of bytes with AudioInputStream skip(long bytes) method . The problem is trying to (let's say a small number of bytes...) : int skipped = audioInputStream.skip(-bytes); always returns 0 as described on this answer Java AudioInputStream skip with negative number of bytes always returns 0 I need to create an implementation which supports also negative number of bytes or something like backwards. Here is the full code of the library on github . What I do is

In Perl, how to “jump over” certain text and do search-and-replace in the remaining part? [duplicate]

南笙酒味 提交于 2019-12-02 13:30:24
This question already has an answer here: How to perform search-and-replace within given $start-$end ranges? 4 answers The text has many occurrences of pattern ; while doing regex find-and-replace, I wanna jump over certain segments of the text, and replace pattern in the remaining part. Example, in the code: #!/usr/bin/env perl use strict; use warnings; #iterate the DATA filehandle while (<DATA>) { # This one replaces ALL occurrences of pattern. s/old/new/gs; # How do I skip the unwanted segments and do the replace? #print all print; } ##inlined data filehandle for testing. __DATA__ START xx

For loop is skipping some stuff! Python

人盡茶涼 提交于 2019-12-02 08:12:13
I'm trying to run this code so that it runs a function for all elements of a list. For illustrative purposes here, basically it should print: '----------Possible Word:', possible_word for all items in my list. So, if I were to input ['p', 'r', 's'] it would run that print 3 times, one for each of those items. My code is below - when I run it it only runs for p and s, not r, which is really odd. Any ideas? def check_matches(input): print 'Input:', input for possible_word in input: print '----------Possible Word:', possible_word valid = True for real_word in word_dictionary: possible_word_list =

Optimize LINQ for IList

点点圈 提交于 2019-11-30 18:59:38
A while ago I wrote an IList extension method to enumerate across part of a list by using the indices. While refactoring I realized a similar query could be performed by calling Skip(toSkip).Take(amount) . While benchmarking this I noticed that Skip isn't optimized for IList . With a bit of googling I ended up at a Jon Skeet post, discussing why optimizing methods like Skip is dangerous . As far as I understand the article, the problem is no exception is thrown in the optimized methods when the collection is modified, but as a comment states the msdn documentation conflicts itself. In