我拥有的Informix-4GL几行代码,其执行以下操作SQL选择Count使用排序
##
# prepare sql
##
let lv_sql = " select table.idno from table ",
" where table.status != 'X' ",
" and table.idno <= 10 ",
" order by table.idno "
prepare table_sel from lv_sql
declare table_cur cursor for table_sel
##
# loop through results and count them
##
let count = 0
foreach table_cur into ti_num
let count = count + 1
end foreach
display count
所以我得到的总的行中的特定表,在正确的不到10序但我需要一个foreach循环相符的总
我做这件事的第二种方式,我喜欢
##
# prepare sql
##
let lv_sql = " select count(table.idno) from table ",
" where table.idno in (",
" select table.idno from table "
" where table.status != 'X' ",
" and table.idno <= 10 ",
") "
prepare table_sel from lv_sql
##
# just get result
##
execute table_sel into count
display count
的问题是,如果我含第二个解决方案崩溃在过滤器中的ude order by子句中,我需要它,因为它并不总是按正确的顺序。在这种情况下有没有办法包括一个命令?
计数如何受订单影响?也就是说,如果你省略了ORDER BY子句,它对计数有什么不同?你应该仔细查看你在做什么,因为排序没有意义,尽管[关于它的意见](http://stackoverflow.com/questions/39343776/sql-select-count-using-ordering#comment66019301_39343884) 。至少,对于订单对点票有重要影响的情况,你有一些认真的解释。 –