답변해 주셔서 감사힙니다.
어려운 숙제를 하나 해결했네요.
적용해 보겠습니다.
civilian 님이 쓰신 글 :
: SELECT FIRST 10 * FROM table_name ORDER BY rand()
:
: 이렇게 하셔도 될듯합니다.
:
: rand() 함수는 파이어버드가 기본으로 제공하는 내장함수가 아니라
: UDF로 추가하셔야 합니다.
:
: SQL 편집 창에서
:
: DECLARE EXTERNAL FUNCTION rand RETURNS DOUBLE PRECISION BY VALUE ENTRY_POINT 'IB_UDF_rand' MODULE_NAME 'ib_udf'
:
: 위 명령을 쓰고 실행 버튼을 누르면 UDF가 추가됩니다.
:
: 동작은 잘 하는군요.
: 덕분에 저도 하나 배웠네요.
:
:
: 최락중 님이 쓰신 글 :
: : 안녕하세요.
: :
: : 테이블에 있는 레코드 중 일부를 무작위로 추출해야 합니다.
: : Firebird FAQ 사이트에서 검색하니 아래와 같은 예가 있는데요.
: : ORDER BY 의 조건식이 언제나 0이 되지 않나요?
: : 0을 만들기 위해 이렇게 복잡하게 쓰진 않았을 것 같구요.
: :
: : 아직 DB가 없어 확인해 보진 못했지만, 고수님의 답변 기다립니다.
: :
: : How to select a random record from a table?
: :
: : There is no such feature in Firebird, but you can use some tricks. The following example requires that you have a unique integer column (primary key is usually used):
: :
: : SELECT ...field_list...
: : FROM table t1
: : WHERE conditions
: : ORDER BY (t1.int_col + seed)*4294967291-((t1.int_col + seed)*4294967291/49157)*49157;
: :
: : If you just need one random record, limit the result set using FIRST or ROWS clause. This query will give consistent records for the same seed. If you wish to be completely random, you need to change the seed. You could use the value of int_col from previous run, or simply fetch a new value from a generator (just make sure the same value for seed is used in both places in expression).
|