我有一个像这样的SQL表:
| SomeID | OtherID | Data
+----------------+-------------+-------------------
| abcdef-..... | cdef123-... | 18,20,22
| abcdef-..... | 4554a24-... | 17,19
| 987654-..... | 12324a2-... | 13,19,20
Run Code Online (Sandbox Code Playgroud)
是否有一个查询,我可以执行查询,如SELECT OtherID, SplitData WHERE SomeID = 'abcdef-.......'
返回单个行,如下所示:
| OtherID | SplitData
+-------------+-------------------
| cdef123-... | 18
| cdef123-... | 20
| cdef123-... | 22
| 4554a24-... | 17
| 4554a24-... | 19
Run Code Online (Sandbox Code Playgroud)
基本上将逗号中的数据拆分成单独的行?
我知道将comma-separated
字符串存储到关系数据库听起来很愚蠢,但消费者应用程序中的正常用例使得这非常有用.
我不想在应用程序中进行拆分,因为我需要分页,因此我想在重构整个应用程序之前探索选项.
这是SQL Server 2008
(非R2).
我很好奇为什么在Python中列表中的尾随逗号是有效的语法,而且似乎Python只是忽略它:
>>> ['a','b',]
['a', 'b']
Run Code Online (Sandbox Code Playgroud)
这是有道理的,当因为它的元组('a')
和('a',)
是两个不同的东西,但在名单?
我想编写一个方法,它将采用一个整数并返回一个std::string
用逗号格式化的整数.
示例声明:
std::string FormatWithCommas(long value);
Run Code Online (Sandbox Code Playgroud)
用法示例:
std::string result = FormatWithCommas(7800);
std::string result2 = FormatWithCommas(5100100);
std::string result3 = FormatWithCommas(201234567890);
// result = "7,800"
// result2 = "5,100,100"
// result3 = "201,234,567,890"
Run Code Online (Sandbox Code Playgroud)
将数字格式化为string
逗号的C++方式是什么?
(奖金也将用于处理double
.)
我想在MySQL中将选定的值转换为逗号分隔的字符串.我的初始代码如下:
SELECT id FROM table_level where parent_id=4;
Run Code Online (Sandbox Code Playgroud)
哪个产生:
'5'
'6'
'9'
'10'
'12'
'14'
'15'
'17'
'18'
'779'
Run Code Online (Sandbox Code Playgroud)
我想要的输出看起来像这样:
"5,6,9,10,12,14,15,17,18,779"
Run Code Online (Sandbox Code Playgroud) 我们可以写一个if
声明
if (a == 5, b == 6, ... , thisMustBeTrue)
Run Code Online (Sandbox Code Playgroud)
只有最后一个条件才能进入if
身体.
为什么允许?
当我尝试使用rmr hadoop shell命令删除此目录时,我已将目录上传到hadoop集群,其名称中包含",",如"MyDir,Name"
hadoop dfs -rmr hdfs://host:port/Navi/MyDir, Name
Run Code Online (Sandbox Code Playgroud)
我收到以下消息rmr:无法删除hdfs:// host:port/Navi/MyDir,:没有这样的文件或目录.rmr:无法删除名称:没有这样的文件或目录.
但是,我已使用相同的命令从同一位置成功删除了其他目录,即
hadoop dfs -rmr hdfs://host:port/dir_path
Run Code Online (Sandbox Code Playgroud)
删除此类目录的任何解决方案.
我有一个连接到我的应用程序的JSON源.其中一个项目是逗号分隔的lat和long.例如:"32.0235,1.345".
我试图通过在逗号处拆分将其拆分为两个单独的值.
有什么建议?谢谢!!
在PHP中,我有一个包含所有字符串的变量数组.存储的某些值是带逗号的数字字符串.
我需要的:
一种从字符串中修剪逗号的方法,只对数字字符串执行此操作.这并不像看起来那么简单.主要原因是以下失败:
$a = "1,435";
if(is_numeric($a))
$a = str_replace(',', '', $a);
Run Code Online (Sandbox Code Playgroud)
这$a = "1435"
是因为数字而失败.但$a = "1,435"
不是数字.因为我得到的一些字符串将是带逗号的常规句子,所以我不能在每个字符串上运行字符串替换.
我可以编写代码if(1) x++, y++;
而不是if(1) {x++; y++;}
,但在某些情况下它不起作用(见下文).如果你告诉我这件事会很好.
int x = 5, y = 10;
if (x == 5) x++, y++; // It works
if (x == 5) x++, return 0; // It shows an error
Run Code Online (Sandbox Code Playgroud)
这同样适用于for
循环:
for (int i = 0; i < 1; i++) y++, y += 5; // It works
for (int i = 0; i < 1; i++) y++, break; // Does not work
Run Code Online (Sandbox Code Playgroud) With reference to Comma-Separated return arguments in C function [duplicate] ,
x=x+2,x+1;
Run Code Online (Sandbox Code Playgroud)
will be evaluated as
x=x+2;
Run Code Online (Sandbox Code Playgroud)
However, in case of the following code
#include<stdlib.h>
#include<stdio.h>
int fun(int x)
{
return (x=x+2,x+1); //[A]
}
int main()
{
int x=5;
x=fun(x);
printf("%d",x); // Output is 8
}
Run Code Online (Sandbox Code Playgroud)
Shouldn't line [A],be evaluated as
x=x+2;
Run Code Online (Sandbox Code Playgroud)
giving x = 7