获取cassandra cql中列值相同的所有行

时间:2018-04-17 13:26:36

标签: database cassandra cql cqlsh

这是我的桌子。

cqlsh:sachhya> select * FROM emp;

 emp_id | age | emp_name     | exp | mobile
--------+-----+--------------+-----+------------
      5 |  29 | RAHUL SHARMA |   9 | 2312343123
      1 |  24 |      SACHHYA |  15 | 9090987876
      2 |  14 |      SACHHYA |  15 | 9090987876
      4 |  22 |        ANKUR |  32 | 3213456321
     90 |  30 |       sumeet |   2 |   91234212
      3 |  14 |      SACHHYA |   3 | 9090987876

PRIMARY KEY(分区键)IS emp_id。

我想显示emp_name为'SACHHYA'的所有行。我应该使用什么命令?

以下是我正在使用的cql查询。

select * FROM emp WHERE emp_name='SACHHYA';

但是我收到了一个错误:

  

InvalidRequest:服务器出错:code = 2200 [查询无效]   message =“非主键列(emp_name)上的谓词尚未出现   支持非二级索引查询“

1 个答案:

答案 0 :(得分:1)

我已经为我的问题找到了一个解决方案,我们可以在' emp_name'上设置索引。之后我们可以使用' emp_name'过滤

EX:

 CREATE INDEX NameIndx ON emp (emp_name);
 SELECT * from sachhya.emp WHERE emp_name = 'SACHHYA';

我的输出:

emp_id | age | desegnation      | emp_name | exp | mobile
--------+-----+------------------+----------+-----+------------
    711 |  22 | Trainee Engineer |  SACHHYA |   1 | 9232189345
      2 |  24 |         Engineer |  SACHHYA |   3 | 9033864540

我的表:

 emp_id | age | desegnation      | emp_name | exp  | mobile
--------+-----+------------------+----------+------+------------
      5 |  29 |   Technical Lead |    RAHUL |    9 | 2312343123
     10 |  45 | Deleviry Manager |   ANDREW |   22 | 9214569345
    711 |  22 | Trainee Engineer |  SACHHYA |    1 | 9232189345
      2 |  24 |         Engineer |  SACHHYA |    3 | 9033864540
      4 |  26 |         Engineer |    ANKUR |    3 | 3213456321
     22 |  20 |           Intern |      SAM | null | 8858699345
      7 |  22 | Trainee Engineer |    JACOB |    1 | 9232189345
     17 |  28 |  Senior Engineer |     JACK |    4 | 8890341799
     90 |  30 |  Senior Engineer | HERCULES |    6 | 9353405163
      3 |  32 |   Technical Lead |     ROSS |    8 | 7876561355