如果您的目标是获得用户的所有订单,那么使用第一种方法是有意义的,例如,
表创建:
create table orders(
userid int,
orderid int,
insDate timeuuid,
primary key(userid,orderid)
);
插入:
insert into orders(userid, orderid, insDate) VALUES(1, 1, now());
insert into orders(userid, orderid, insDate) VALUES(1, 2, now());
insert into orders(userid, orderid, insDate) VALUES(2, 3, now());
insert into orders(userid, orderid, insDate) VALUES(3, 4, now());
查询:
>select userid,dateof(insdate),orderid from orders where userid in(1,2);
userid | dateof(insdate) | orderid
--------+--------------------------+---------
1 | 2013-11-06 17:26:56+0000 | 1
1 | 2013-11-06 17:26:59+0000 | 2
2 | 2013-11-06 17:27:02+0000 | 3
(3 rows)
(用 测试过[cqlsh 4.0.1 | Cassandra 2.0.1 | CQL spec 3.1.1 | Thrift protocol 19.37.0]
。)