MySQL中的JSON where条件
我有以下JSON列表:“[Foo,Bar]” 以下条目位于my MySQL表t中 有没有一种方法可以将我的JSON列表用作我的where子句中的一个条件,并获得相同的结果,如:MySQL中的JSON where条件,mysql,json,mariadb,Mysql,Json,Mariadb,我有以下JSON列表:“[Foo,Bar]” 以下条目位于my MySQL表t中 有没有一种方法可以将我的JSON列表用作我的where子句中的一个条件,并获得相同的结果,如: ?据我所知,您可以在SQL查询中放置多个WHERE语句 见: 您只需在每个条件后添加一个“AND”或“or” SELECT * FROM Customers WHERE Country='Mexico' AND Address='Avda. de la Constitución 2222' OR Ad
?据我所知,您可以在SQL查询中放置多个WHERE语句 见: 您只需在每个条件后添加一个“AND”或“or”
SELECT * FROM Customers
WHERE Country='Mexico'
AND Address='Avda. de la Constitución 2222'
OR Address='Mataderos 2312';
;
因此,您只需在使用之前构建所需的字符串
使用c,您可以执行以下操作,如just和operators:
public List<Data> ExecuteQueryAND(List<string> statements, string table)
{
// initial connection
// ...
string str = $"SELECT * FROM {table}\n";
for (int i =0; i > statements.Count; i++)
{
if( i == 0 )
{
str = str + $"WHERE {statements[i]}\n";
}
str = str + $"\tAND {statements[i]}\n";
}
str = str + ";";
Console.WriteLine("Sql Query: " + str);
// more code to execute sql
}
那么当你叫它:
// some code ..
FilterList = ExecuteQueryAND( new List<string> { "Access=\"ADMIN\""});
// more code ..
Akina解决了这个问题:
从t中选择*其中JSON_包含“[Foo,Bar]”、CONCAT“”、Name“”,其中JSON_包含@JSON_list、CONCAT“”、Name“”,可以是这么简单。非常感谢!但是请注意,您缺少一个结束语。您可以在这里测试示例查询我希望它有所帮助,如果您有更多问题,请让我现在为您的答案添加一些进一步的解释。据我所知,在所有JSON列表将输入函数条目上的列表内容之后,您不会使用该JSON列表。我认为您应该将注释转换为答案@Akina
public List<Data> ExecuteQueryAND(List<string> statements, string table)
{
// initial connection
// ...
string str = $"SELECT * FROM {table}\n";
for (int i =0; i > statements.Count; i++)
{
if( i == 0 )
{
str = str + $"WHERE {statements[i]}\n";
}
str = str + $"\tAND {statements[i]}\n";
}
str = str + ";";
Console.WriteLine("Sql Query: " + str);
// more code to execute sql
}
// some code ..
FilterList = ExecuteQueryAND( new List<string> { "Access=\"ADMIN\""});
// more code ..