我知道我可以在SQLite查询中使用CASE语句,但是我不知道如何在WHERE子句中构建它。
实际上,我在很长的WHERE子句中有此内容(这只是问题所关注的部分):
AND (%d >= (wines.year + wines.maturity)) AND (%d < (wines.year + wines.apogee))
Run Code Online (Sandbox Code Playgroud)
实际上我只想要:
AND (%d >= (wines.year + wines.maturity))
Run Code Online (Sandbox Code Playgroud)
=>如果wines.apogee为NULL
或者:
AND (%d >= (wines.year + wines.maturity)) AND (%d < (wines.year + wines.apogee))
Run Code Online (Sandbox Code Playgroud)
=>如果wines.apogee不为空
在这种情况下,如何使用CASE语句测试wines.apogee是否为NULL并在这种情况下添加请求的第二部分?
谢谢 !
我想拆分一个主字符串,并用Ruby中获得的单词创建多个字符串.
str = "one two three four five"
Run Code Online (Sandbox Code Playgroud)
我想在一个字符串数组中创建所有这些可能性:
"one"
"one two"
"one two three"
"one two three four"
"one two three four five"
Run Code Online (Sandbox Code Playgroud)
但是也:
"two three four five"
"three four five"
"four five"
"five"
Run Code Online (Sandbox Code Playgroud)
理想情况下我也会在里面获取字符串,但不是必需的:
"two three four"
"two three"
"three four"
Run Code Online (Sandbox Code Playgroud)
我尝试了很多东西,但很难有最好的方法来做到这一点.
例如,我尝试使用each_slice:
words = string.split(" ")
number_of_words = words.length
max_number_of_slices = number_of_words
array_of_strings_to_match = []
number_of_slices = 1
while (number_of_slices <= max_number_of_slices)
array = words.each_slice(number_of_slices).map do |a| a.join ' ' end
array.each do |w| array_of_strings_to_match << w …Run Code Online (Sandbox Code Playgroud) 我只想在模式之后的下一个字母是给定的一个字母时替换Ruby中的模式.
示例:将"αυ"替换为"av"仅在"αυ"之后的下一个字母为以下之一时:α|γ|δ|λ|μ|ν|ρ|σμ|ω
这个代码当然不会起作用,我想我需要使用正则表达式更复杂来匹配模式之后的一个字母.
string.gsub!("??", "av") if string =~ /?|?|?|?|?|?|?|??|?/
Run Code Online (Sandbox Code Playgroud)
谢谢你的任何建议.
我有一个转换一个brut JSON字符串日期的问题:
"created_at"="2012-12-22T21:39:22Z";
进入NSDate.
这是我目前的类别:
- (NSDate*)dateWithJSONString
{
[NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
[dateFormatter setCalendar:[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]];
NSDate *date = [[NSDate alloc] init];
date = [dateFormatter dateFromString:self];
return date;
}
Run Code Online (Sandbox Code Playgroud)
问题是95%的情况都适用,但如果某些用户在日期和时间设置与自定义国际设置相结合时使用AM/PM而不是24H,则不会从json字符串创建日期.
我阅读了这个讨论,但我找不到与我所有国际用户和设置合作的好方法.
我添加了这个例子:
[dateFormatter setLocale:[NSLocale currentLocale]];
Run Code Online (Sandbox Code Playgroud)
但它什么都没改变.如果我将我的iPhone设置为AM/PM而不是24H,则不会创建NSDate.
AM/PM NSDate架构:2013-01-21 07:12:43 AM +0000
24H NSDate架构:2013-01-21 07:12:43 +0000
我错过了什么 ?是否有更新的日期格式?
我正在尝试为我的 ElasticSearch 快照创建一个备份存储库。
curl -XPUT 'http://localhost:9200/_snapshot/backup' -d '{
"type": "fs",
"settings": {
"location": "/home/admin/dumps/elasticsearch",
"compress": true
}
}'
Run Code Online (Sandbox Code Playgroud)
我得到的问题是:
{"error":{"root_cause":[{"type":"repository_exception","reason":"[backup] 无法创建存储库"}],...
我很确定这是我的目录中的正确/用户问题。
我试过:
chmod 777 /home/admin/dumps/elasticsearch
Run Code Online (Sandbox Code Playgroud)
实际上回购权是:
drwxrwxrwx 2 admin admin 4096 Jan 6 14:39 elasticsearch
Run Code Online (Sandbox Code Playgroud)
但我有同样的问题。
我也尝试过使用 sudo 卷曲(同样的问题)。
好吧,我现在迷路了。;-) 提前致谢。