我想使用Oracle
查询我的ROWNUM
数据。
格式如下:
SELECT *
FROM
(
SELECT
ACTIVITYNAME, rownum AS rnum
FROM
(
SELECT ACTIVITYNAME
FROM
WA_GA_TBL_ACTIVITY
ORDER BY ACTIVITYNAME)
WHERE rownum <= 20
)
WHERE rnum > 10
我想要的完整查询就像这样:
SELECT * FROM
(
SELECT
A.ACTIVITYID,
A.ACTIVITYNAME,
A.GROUPID_FK,
TO_CHAR(A.ACTIVITYDATE, 'DD-MON-YYYY HH24:MI:SS') AS ACTIVITYDATES,
U.GROUPID_FK,
U.FIRSTNAME,
U.LASTNAME,
U.USERAVATAR
FROM
WA_GA_TBL_ACTIVITY A,
WA_GA_TBL_USERS U
WHERE
A.USERID_FK = U.USERID AND
A.USERID_FK != '" . $getUserID . "' AND
(A.GROUPID_FK = '" . $getGroupIDFK . "' OR (A.GROUPID_FK_TO LIKE ('%" . $getGroupIDFK . "%')) OR ((A.USERID_FK_TO IS NOT NULL AND A.USERID_FK_TO = '" . $getUserID . "'))) AND
A.ACTIVITYID IN(SELECT ACTIVITYID_FK FROM WA_GA_TBL_ACCESSACTIVITY WHERE USERID_FK = '" . $getUserID . "') AND
ROWNUM <= 20
ORDER BY A.ACTIVITYDATE DESC
)
WHERE ROWNUM <= 10
当我尝试运行查询时,它会显示错误:ORA-00918: column ambiguously defined
答案 0 :(得分:0)
内部查询有2个“groupid_fk”你需要将其中一个替换为其他名称以使外部查询起作用。我在下面格式化了8行和10行。
也不确定这是什么语言,但是对于第19,21,22,26,37行中的SQL注入而言
SQL> format buffer
1 SELECT
2 *
3 FROM
4 (
5 SELECT
6 a.activityid,
7 a.activityname,
8 a.groupid_fk,
9 TO_CHAR(a.activitydate,'DD-MON-YYYY HH24:MI:SS') AS activitydates,
10 u.groupid_fk,
11 u.firstname,
12 u.lastname,
13 u.useravatar
14 FROM
15 wa_ga_tbl_activity a,
16 wa_ga_tbl_users u
17 WHERE
18 a.userid_fk = u.userid
19 AND a.userid_fk != '" . $getUserID . "'
20 AND (
21 a.groupid_fk = '" . $getGroupIDFK . "'
22 OR ( a.groupid_fk_to LIKE ( '%" . $getGroupIDFK . "%' ) )
23 OR (
24 (
25 a.userid_fk_to IS NOT NULL
26 AND a.userid_fk_to = '" . $getUserID . "'
27 )
28 )
29 )
30 AND a.activityid IN (
31 SELECT
32 activityid_fk
33 FROM
34 wa_ga_tbl_accessactivity
35 WHERE
36 userid_fk = '" . $getUserID . "'
37 )
38 AND ROWNUM <= 20
39 ORDER BY
40 a.activitydate DESC
41 )
42 WHERE
43* ROWNUM <= 10
SQL>