Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/52.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL中的JSON where条件_Mysql_Json_Mariadb - Fatal编程技术网

MySQL中的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

我有以下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 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 ..