我想从一个巨大的表中获得所有记录,其中number
列中的任何一列的计数值都大于0
。什么是最好的方式来做到这一点?对具有特定列值的记录的Oracle SQL“元”查询
例如为:
/* table structure*/
create table sometable (id number,
somestring varchar2(12),
some_amount_1 number(17,3),
some_amount_2 number(17,3),
some_amount_3 number(17,3),
...
some_amount_xxx number(17,3));
/* "xxx" > 100, and yeah I did not designed that table structure... */
而且我想任何行,其中任何some_amount_n > 0
的(甚至更好的解决方案是在显示的字段(一个或多个第一位置添加一个字段)大于零)。
我知道我可以用一个巨大的some_amount_1 > 0 OR some_amount_2 > 0 OR ...
块(与一些case when
字段名写这个,但应该有一些更优雅的解决方案,是不是有
优雅的解决方案是通过有一个数字列规范化您的表。 Instaed of> 100'some_amount_X'列,创建一个只有4列的表:'(id,somestring,X,some_amount)' –
也许你是对的@ypercube,但我不能这样做:没有权限那并不能强迫那些拥有。 –
如果数字是非负数,则在'select'的'where'子句中添加所有数字并检查总和是否大于' – Raihan