如何返回共享值的列的名称?

时间:2016-11-11 20:14:46

标签: java android sql sqlite

我试图返回共享值的列的名称。我以为我可以对数据库进行查询,并提取名称。

例如,当我的共享值为Director时,我想返回ActorsTarantino列,因为他既是演员又是导演。

String x = "Tarantino";

String q =
        "SELECT Actors, Director, Genre, Country, Released, WHERE Actors LIKE '%"+x+"%' " +
        "AND WHERE Director LIKE  '%"+x+"%' " +
        "AND WHERE Genre LIKE  '%"+x+"%' " +
        "AND WHERE Country LIKE  '%"+x+"%' " +
        "AND WHERE Released LIKE  '%"+x+"%' " ;

然后我可以迭代光标并获取列名DirectorActors

1 个答案:

答案 0 :(得分:0)

要在一列中查找匹配项,请尝试以下操作:

select exists (select * from actors where director like '%"+x+"%');

要将所有四个放在一起,您可以尝试:

select q1, q2, q3, q4 
from
  (select exists (...) as q1)
  join
  (select exists (...) as q2)
  join
  (select exists (...) as q3)
  join
  (select exists (...) as q4)

取代:

你试过了吗?

    "SELECT Actors, Director, Genre, Country, Released, WHERE Actors LIKE '%"+x+"%' " +
    "AND Director LIKE  '%"+x+"%' " +
    "AND Genre LIKE  '%"+x+"%' " +
    "AND Country LIKE  '%"+x+"%' " +
    "AND Released LIKE  '%"+x+"%' " ;

请注意SELECT的工作方式,它返回所有列。您的查询应返回符合所有四个条件的。但是,我认为你正在尝试做一些与众不同的事情。究竟是什么我不清楚。