Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
495 views
in Technique[技术] by (71.8m points)

请问下像这种复合过滤条件的SQL语句该怎样写?

我在DolphinDB Database GUI中执行下列语句:

opened = select * from tradeinfo where (openclose=0, (status=1 || status=2)) || (openclose=1, (status=0 || status=3));

报异常:Please use logical expressions to represent filtering criteria.请问这个应该怎么改?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

如果只是解决上面这个问题。可以改写如下:

opened = select * from tradeinfo where (openclose=0 and (status=1 || status=2)) || (openclose=1 and (status=0 || status=3))

这儿openClose只有两个状态,status只有4个状态。但是更一般的情况,如果状态比较多, 上面的做法不但代码繁琐,而且效率低下。这种情况下可以使用DolphinDB的condtionalFilter函数来实现。上面的例子可以改写为:

filterDict = dict([0, 1], [1 2, 0 3])
opened = select  from tradeinfo where conditionalFilter(status, openClose, filterDict)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...