我擁有的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) 。至少,對於訂單對點票有重要影響的情況,你有一些認真的解釋。 –