when i code
select
row_.*, rownum rownum_
from
(select
topic0_.id as id6_, topic0_.title as title6_,
topic0_.publish_author_id as publish3_6_, topic0_.reply_number as reply4_6_,
topic0_.read_number as read5_6_, topic0_.publish_author_name as publish6_6_,
topic0_.publish_time as publish7_6_, topic0_.last_reply_time as last8_6_,
topic0_.last_reply_name as last9_6_, topic0_.main_text as main10_6_, topic0_.FORUM_ID as FORUM11_6_
from topic topic0_
where topic0_.FORUM_ID='16F37E59FE494AC9B17A2340387335EF'
order by
case when topic0_.last_reply_time is not null then topic0_.last_reply_time
else topic0_.publish_time end desc
) row_;
the result:
ID6_ TITLE6_ PUBLISH3_6_ REPLY4_6_ READ5_6_ PUBLISH6_6_ PUBLISH7_6_ LAST8_6_ LAST9_6_ MAIN10_6_ FORUM11_6_ ROWNUM_
1 402840713e108ea4013e1090c95c0001 trytr 2 2 0 ss 2013-4-16 9:58:44 2013-4-16 9:59:21 ss fdsfds 16F37E59FE494AC9B17A2340387335EF 1
2 402840713e108ea4013e1090127e0000 trytr 2 0 0 ss 2013-4-16 9:57:57 ytrytr 16F37E59FE494AC9B17A2340387335EF 2
3 402840713e0d3616013e0d3618c20000 cde0 2 0 0 ss 2013-4-15 18:20:49 abc0 16F37E59FE494AC9B17A2340387335EF 3
4 402840713e0d3616013e0d3618da0063 cde99 2 0 0 ss 2013-4-15 18:20:49 abc99 16F37E59FE494AC9B17A2340387335EF 4
5 402840713e0d3616013e0d3618da0062 cde98 2 0 0 ss 2013-4-15 18:20:49 abc98 16F37E59FE494AC9B17A2340387335EF 5
6 402840713e0d3616013e0d3618da0061 cde97 2 0 0 ss 2013-4-15 18:20:49 abc97 16F37E59FE494AC9B17A2340387335EF 6
7 402840713e0d3616013e0d3618da0060 cde96 2 0 0 ss 2013-4-15 18:20:49 abc96 16F37E59FE494AC9B17A2340387335EF 7
8 402840713e0d3616013e0d3618da005f cde95 2 0 0 ss 2013-4-15 18:20:49 abc95 16F37E59FE494AC9B17A2340387335EF 8
9 402840713e0d3616013e0d3618da005e cde94 2 0 0 ss 2013-4-15 18:20:49 abc94 16F37E59FE494AC9B17A2340387335EF 9
10 402840713e0d3616013e0d3618da005d cde93 2 0 0 ss 2013-4-15 18:20:49 abc93 16F37E59FE494AC9B17A2340387335EF 10
11 402840713e0d3616013e0d3618da005c cde92 2 0 0 ss 2013-4-15 18:20:49 abc92 16F37E59FE494AC9B17A2340387335EF 11
12 402840713e0d3616013e0d3618da005b cde91 2 0 0 ss 2013-4-15 18:20:49 abc91 16F37E59FE494AC9B17A2340387335EF 12
13 402840713e0d3616013e0d3618d9005a cde90 2 0 0 ss 2013-4-15 18:20:49 abc90 16F37E59FE494AC9B17A2340387335EF 13
14 402840713e0d3616013e0d3618d90059 cde89 2 0 0 ss 2013-4-15 18:20:49 abc89 16F37E59FE494AC9B17A2340387335EF 14
15 402840713e0d3616013e0d3618d90058 cde88 2 0 0 ss 2013-4-15 18:20:49 abc88 16F37E59FE494AC9B17A2340387335EF 15
16 402840713e0d3616013e0d3618d90057 cde87 2 0 0 ss 2013-4-15 18:20:49 abc87 16F37E59FE494AC9B17A2340387335EF 16
17 402840713e0d3616013e0d3618d90056 cde86 2 0 0 ss 2013-4-15 18:20:49 abc86 16F37E59FE494AC9B17A2340387335EF 17
18 402840713e0d3616013e0d3618d90055 cde85 2 0 0 ss 2013-4-15 18:20:49 abc85 16F37E59FE494AC9B17A2340387335EF 18
19 402840713e0d3616013e0d3618d90054 cde84 2 0 0 ss 2013-4-15 18:20:49 abc84 16F37E59FE494AC9B17A2340387335EF 19
20 402840713e0d3616013e0d3618d90053 cde83 2 0 0 ss 2013-4-15 18:20:49 abc83 16F37E59FE494AC9B17A2340387335EF 20
21 402840713e0d3616013e0d3618d90052 cde82 2 0 0 ss 2013-4-15 18:20:49 abc82 16F37E59FE494AC9B17A2340387335EF 21
22 402840713e0d3616013e0d3618d90051 cde81 2 0 0 ss 2013-4-15 18:20:49 abc81 16F37E59FE494AC9B17A2340387335EF 22
23 402840713e0d3616013e0d3618d80050 cde80 2 0 0 ss 2013-4-15 18:20:49 abc80 16F37E59FE494AC9B17A2340387335EF 23
24 402840713e0d3616013e0d3618d8004f cde79 2 0 0 ss 2013-4-15 18:20:49 abc79 16F37E59FE494AC9B17A2340387335EF 24
25 402840713e0d3616013e0d3618d8004e cde78 2 0 0 ss 2013-4-15 18:20:49 abc78 16F37E59FE494AC9B17A2340387335EF 25
26 402840713e0d3616013e0d3618d8004d cde77 2 0 0 ss 2013-4-15 18:20:49 abc77 16F37E59FE494AC9B17A2340387335EF 26
27 402840713e0d3616013e0d3618d8004c cde76 2 0 0 ss 2013-4-15 18:20:49 abc76 16F37E59FE494AC9B17A2340387335EF 27
28 402840713e0d3616013e0d3618d8004b cde75 2 0 0 ss 2013-4-15 18:20:49 abc75 16F37E59FE494AC9B17A2340387335EF 28
29 402840713e0d3616013e0d3618d8004a cde74 2 0 0 ss 2013-4-15 18:20:49 abc74 16F37E59FE494AC9B17A2340387335EF 29
30 402840713e0d3616013e0d3618d80049 cde73 2 0 0 ss 2013-4-15 18:20:49 abc73 16F37E59FE494AC9B17A2340387335EF 30
31 402840713e0d3616013e0d3618d80048 cde72 2 0 0 ss 2013-4-15 18:20:49 abc72 16F37E59FE494AC9B17A2340387335EF 31
32 402840713e0d3616013e0d3618d70047 cde71 2 0 0 ss 2013-4-15 18:20:49 abc71 16F37E59FE494AC9B17A2340387335EF 32
33 402840713e0d3616013e0d3618d70046 cde70 2 0 0 ss 2013-4-15 18:20:49 abc70 16F37E59FE494AC9B17A2340387335EF 33
34 402840713e0d3616013e0d3618d70045 cde69 2 0 0 ss 2013-4-15 18:20:49 abc69 16F37E59FE494AC9B17A2340387335EF 34
35 402840713e0d3616013e0d3618d70044 cde68 2 0 0 ss 2013-4-15 18:20:49 abc68 16F37E59FE494AC9B17A2340387335EF 35
36 402840713e0d3616013e0d3618d70043 cde67 2 0 0 ss 2013-4-15 18:20:49 abc67 16F37E59FE494AC9B17A2340387335EF 36
37 402840713e0d3616013e0d3618d70042 cde66 2 0 0 ss 2013-4-15 18:20:49 abc66 16F37E59FE494AC9B17A2340387335EF 37
38 402840713e0d3616013e0d3618d70041 cde65 2 0 0 ss 2013-4-15 18:20:49 abc65 16F37E59FE494AC9B17A2340387335EF 38
39 402840713e0d3616013e0d3618d70040 cde64 2 0 0 ss 2013-4-15 18:20:49 abc64 16F37E59FE494AC9B17A2340387335EF 39
40 402840713e0d3616013e0d3618d7003f cde63 2 0 0 ss 2013-4-15 18:20:49 abc63 16F37E59FE494AC9B17A2340387335EF 40
41 402840713e0d3616013e0d3618d7003e cde62 2 0 0 ss 2013-4-15 18:20:49 abc62 16F37E59FE494AC9B17A2340387335EF 41
42 402840713e0d3616013e0d3618d6003d cde61 2 0 0 ss 2013-4-15 18:20:49 abc61 16F37E59FE494AC9B17A2340387335EF 42
43 402840713e0d3616013e0d3618d6003c cde60 2 0 0 ss 2013-4-15 18:20:49 abc60 16F37E59FE494AC9B17A2340387335EF 43
44 402840713e0d3616013e0d3618d6003b cde59 2 0 0 ss 2013-4-15 18:20:49 abc59 16F37E59FE494AC9B17A2340387335EF 44
45 402840713e0d3616013e0d3618d6003a cde58 2 0 0 ss 2013-4-15 18:20:49 abc58 16F37E59FE494AC9B17A2340387335EF 45
46 402840713e0d3616013e0d3618d60039 cde57 2 0 0 ss 2013-4-15 18:20:49 abc57 16F37E59FE494AC9B17A2340387335EF 46
47 402840713e0d3616013e0d3618d60038 cde56 2 0 0 ss 2013-4-15 18:20:49 abc56 16F37E59FE494AC9B17A2340387335EF 47
48 402840713e0d3616013e0d3618d60037 cde55 2 0 0 ss 2013-4-15 18:20:49 abc55 16F37E59FE494AC9B17A2340387335EF 48
49 402840713e0d3616013e0d3618d60036 cde54 2 0 0 ss 2013-4-15 18:20:49 abc54 16F37E59FE494AC9B17A2340387335EF 49
50 402840713e0d3616013e0d3618d60035 cde53 2 0 0 ss 2013-4-15 18:20:49 abc53 16F37E59FE494AC9B17A2340387335EF 50
51 402840713e0d3616013e0d3618d50034 cde52 2 0 0 ss 2013-4-15 18:20:49 abc52 16F37E59FE494AC9B17A2340387335EF 51
52 402840713e0d3616013e0d3618d50033 cde51 2 0 0 ss 2013-4-15 18:20:49 abc51 16F37E59FE494AC9B17A2340387335EF 52
53 402840713e0d3616013e0d3618d50032 cde50 2 0 0 ss 2013-4-15 18:20:49 abc50 16F37E59FE494AC9B17A2340387335EF 53
54 402840713e0d3616013e0d3618d50031 cde49 2 0 0 ss 2013-4-15 18:20:49 abc49 16F37E59FE494AC9B17A2340387335EF 54
55 402840713e0d3616013e0d3618d50030 cde48 2 0 0 ss 2013-4-15 18:20:49 abc48 16F37E59FE494AC9B17A2340387335EF 55
56 402840713e0d3616013e0d3618d5002f cde47 2 0 0 ss 2013-4-15 18:20:49 abc47 16F37E59FE494AC9B17A2340387335EF 56
57 402840713e0d3616013e0d3618d5002e cde46 2 0 0 ss 2013-4-15 18:20:49 abc46 16F37E59FE494AC9B17A2340387335EF 57
58 402840713e0d3616013e0d3618d5002d cde45 2 0 0 ss 2013-4-15 18:20:49 abc45 16F37E59FE494AC9B17A2340387335EF 58
59 402840713e0d3616013e0d3618d5002c cde44 2 0 0 ss 2013-4-15 18:20:49 abc44 16F37E59FE494AC9B17A2340387335EF 59
60 402840713e0d3616013e0d3618d5002b cde43 2 0 0 ss 2013-4-15 18:20:49 abc43 16F37E59FE494AC9B17A2340387335EF 60
61 402840713e0d3616013e0d3618d5002a cde42 2 0 0 ss 2013-4-15 18:20:49 abc42 16F37E59FE494AC9B17A2340387335EF 61
62 402840713e0d3616013e0d3618d40029 cde41 2 0 0 ss 2013-4-15 18:20:49 abc41 16F37E59FE494AC9B17A2340387335EF 62
63 402840713e0d3616013e0d3618d40028 cde40 2 0 0 ss 2013-4-15 18:20:49 abc40 16F37E59FE494AC9B17A2340387335EF 63
64 402840713e0d3616013e0d3618d40027 cde39 2 0 0 ss 2013-4-15 18:20:49 abc39 16F37E59FE494AC9B17A2340387335EF 64
65 402840713e0d3616013e0d3618d40026 cde38 2 0 0 ss 2013-4-15 18:20:49 abc38 16F37E59FE494AC9B17A2340387335EF 65
66 402840713e0d3616013e0d3618d40025 cde37 2 0 0 ss 2013-4-15 18:20:49 abc37 16F37E59FE494AC9B17A2340387335EF 66
67 402840713e0d3616013e0d3618d40024 cde36 2 0 0 ss 2013-4-15 18:20:49 abc36 16F37E59FE494AC9B17A2340387335EF 67
68 402840713e0d3616013e0d3618d40023 cde35 2 0 0 ss 2013-4-15 18:20:49 abc35 16F37E59FE494AC9B17A2340387335EF 68
69 402840713e0d3616013e0d3618d40022 cde34 2 0 0 ss 2013-4-15 18:20:49 abc34 16F37E59FE494AC9B17A2340387335EF 69
70 402840713e0d3616013e0d3618d30021 cde33 2 0 0 ss 2013-4-15 18:20:49 abc33 16F37E59FE494AC9B17A2340387335EF 70
71 402840713e0d3616013e0d3618d30020 cde32 2 0 0 ss 2013-4-15 18:20:49 abc32 16F37E59FE494AC9B17A2340387335EF 71
72 402840713e0d3616013e0d3618d3001f cde31 2 0 0 ss 2013-4-15 18:20:49 abc31 16F37E59FE494AC9B17A2340387335EF 72
73 402840713e0d3616013e0d3618d3001e cde30 2 0 0 ss 2013-4-15 18:20:49 abc30 16F37E59FE494AC9B17A2340387335EF 73
74 402840713e0d3616013e0d3618d3001d cde29 2 0 0 ss 2013-4-15 18:20:49 abc29 16F37E59FE494AC9B17A2340387335EF 74
75 402840713e0d3616013e0d3618d3001c cde28 2 0 0 ss 2013-4-15 18:20:49 abc28 16F37E59FE494AC9B17A2340387335EF 75
76 402840713e0d3616013e0d3618d3001b cde27 2 0 0 ss 2013-4-15 18:20:49 abc27 16F37E59FE494AC9B17A2340387335EF 76
77 402840713e0d3616013e0d3618d3001a cde26 2 0 0 ss 2013-4-15 18:20:49 abc26 16F37E59FE494AC9B17A2340387335EF 77
78 402840713e0d3616013e0d3618d30019 cde25 2 0 0 ss 2013-4-15 18:20:49 abc25 16F37E59FE494AC9B17A2340387335EF 78
79 402840713e0d3616013e0d3618d30018 cde24 2 0 0 ss 2013-4-15 18:20:49 abc24 16F37E59FE494AC9B17A2340387335EF 79
80 402840713e0d3616013e0d3618d20017 cde23 2 0 0 ss 2013-4-15 18:20:49 abc23 16F37E59FE494AC9B17A2340387335EF 80
81 402840713e0d3616013e0d3618d20016 cde22 2 0 0 ss 2013-4-15 18:20:49 abc22 16F37E59FE494AC9B17A2340387335EF 81
82 402840713e0d3616013e0d3618d20015 cde21 2 0 0 ss 2013-4-15 18:20:49 abc21 16F37E59FE494AC9B17A2340387335EF 82
83 402840713e0d3616013e0d3618d20014 cde20 2 0 0 ss 2013-4-15 18:20:49 abc20 16F37E59FE494AC9B17A2340387335EF 83
84 402840713e0d3616013e0d3618d20013 cde19 2 0 0 ss 2013-4-15 18:20:49 abc19 16F37E59FE494AC9B17A2340387335EF 84
85 402840713e0d3616013e0d3618d20012 cde18 2 0 0 ss 2013-4-15 18:20:49 abc18 16F37E59FE494AC9B17A2340387335EF 85
86 402840713e0d3616013e0d3618d20011 cde17 2 0 0 ss 2013-4-15 18:20:49 abc17 16F37E59FE494AC9B17A2340387335EF 86
87 402840713e0d3616013e0d3618d20010 cde16 2 0 0 ss 2013-4-15 18:20:49 abc16 16F37E59FE494AC9B17A2340387335EF 87
88 402840713e0d3616013e0d3618d0000f cde15 2 0 0 ss 2013-4-15 18:20:49 abc15 16F37E59FE494AC9B17A2340387335EF 88
89 402840713e0d3616013e0d3618cf000e cde14 2 0 0 ss 2013-4-15 18:20:49 abc14 16F37E59FE494AC9B17A2340387335EF 89
90 402840713e0d3616013e0d3618cf000d cde13 2 0 0 ss 2013-4-15 18:20:49 abc13 16F37E59FE494AC9B17A2340387335EF 90
91 402840713e0d3616013e0d3618cf000c cde12 2 0 0 ss 2013-4-15 18:20:49 abc12 16F37E59FE494AC9B17A2340387335EF 91
92 402840713e0d3616013e0d3618cf000b cde11 2 0 0 ss 2013-4-15 18:20:49 abc11 16F37E59FE494AC9B17A2340387335EF 92
93 402840713e0d3616013e0d3618cf000a cde10 2 0 0 ss 2013-4-15 18:20:49 abc10 16F37E59FE494AC9B17A2340387335EF 93
94 402840713e0d3616013e0d3618ce0009 cde9 2 0 0 ss 2013-4-15 18:20:49 abc9 16F37E59FE494AC9B17A2340387335EF 94
95 402840713e0d3616013e0d3618ce0008 cde8 2 0 0 ss 2013-4-15 18:20:49 abc8 16F37E59FE494AC9B17A2340387335EF 95
96 402840713e0d3616013e0d3618ce0007 cde7 2 0 0 ss 2013-4-15 18:20:49 abc7 16F37E59FE494AC9B17A2340387335EF 96
97 402840713e0d3616013e0d3618ce0006 cde6 2 0 0 ss 2013-4-15 18:20:49 abc6 16F37E59FE494AC9B17A2340387335EF 97
98 402840713e0d3616013e0d3618ce0005 cde5 2 0 0 ss 2013-4-15 18:20:49 abc5 16F37E59FE494AC9B17A2340387335EF 98
99 402840713e0d3616013e0d3618ce0004 cde4 2 0 0 ss 2013-4-15 18:20:49 abc4 16F37E59FE494AC9B17A2340387335EF 99
100 402840713e0d3616013e0d3618ce0003 cde3 2 0 0 ss 2013-4-15 18:20:49 abc3 16F37E59FE494AC9B17A2340387335EF 100
101 402840713e0d3616013e0d3618ce0002 cde2 2 0 0 ss 2013-4-15 18:20:49 abc2 16F37E59FE494AC9B17A2340387335EF 101
102 402840713e0d3616013e0d3618cd0001 cde1 2 0 0 ss 2013-4-15 18:20:49 abc1 16F37E59FE494AC9B17A2340387335EF 102
103 402840713e0cb39c013e0cb41c040000 dfsdf 2 1 0 ss 2013-4-15 15:58:50 sdfsdfsdf 16F37E59FE494AC9B17A2340387335EF 103
104 402840713e0c9424013e0c94a8c30000 fffff 2 1 0 ss 2013-4-15 15:24:29 dgfdgfdg 16F37E59FE494AC9B17A2340387335EF 104
105 402840713e0c8e00013e0c8f1d190000 asf 2 2 0 ss 2013-4-15 15:18:25 dsfds 16F37E59FE494AC9B17A2340387335EF 105
106 402840713e0c80ce013e0c8158630000 ccc 2 1 0 ss 2013-4-15 15:03:23 dfsd 16F37E59FE494AC9B17A2340387335EF 106
107 402840713e0c5a97013e0c5b0c200000 hhhhh 2 2 0 ss 2013-4-15 14:21:33 fds 16F37E59FE494AC9B17A2340387335EF 107
108 402840713e0c58cd013e0c592b550000 hff 2 0 0 ss 2013-4-15 14:19:30 sdfs 16F37E59FE494AC9B17A2340387335EF 108
109 402840713e0c272d013e0c2e12c40000 gsfsdf 2 0 0 ss 2013-4-15 13:32:26 fdsfds 16F37E59FE494AC9B17A2340387335EF 109
110 402840713e0c25ef013e0c265f720000 fdsf 2 0 0 ss 2013-4-15 13:24:01 fsdfsdf 16F37E59FE494AC9B17A2340387335EF 110
111 402840713e0c2237013e0c228d4b0000 fdsf 2 0 0 ss 2013-4-15 13:19:51 sdfs 16F37E59FE494AC9B17A2340387335EF 111
112 402840713e0c1cc9013e0c1d0dc30000 fsdf 2 0 0 ss 2013-4-15 13:13:50 sdfdsfds 16F37E59FE494AC9B17A2340387335EF 112
113 402840713e0c1be8013e0c1c33bf0000 fsfds 2 0 0 ss 2013-4-15 13:12:54 fdsfsd 16F37E59FE494AC9B17A2340387335EF 113
114 402840713e0c1b0b013e0c1b72320000 fsfsd 2 0 0 ss 2013-4-15 13:12:05 fsdfsd 16F37E59FE494AC9B17A2340387335EF 114
115 402840713e0c19a9013e0c19f49b0000 GDFG 2 0 0 ss 2013-4-15 13:10:27 FDGDFGDF 16F37E59FE494AC9B17A2340387335EF 115
116 402840713e0c17c7013e0c184b200000 fdsfsd 2 0 0 ss 2013-4-15 13:08:38 fsdfsdfs 16F37E59FE494AC9B17A2340387335EF 116
117 402840713e0c0edc013e0c0f79d20000 fsdfds 2 0 0 ss 2013-4-15 12:59:00 fdsfdsfdsfd 16F37E59FE494AC9B17A2340387335EF 117
118 402840713e0bee4f013e0bef28150000 fdsfsd 2 0 0 ss 2013-4-15 12:23:42 fdsfsdf 16F37E59FE494AC9B17A2340387335EF 118
119 402840713e0b92fc013e0b9418cf0000 fdsfdsf 2 0 0 ss 2013-4-15 10:44:15 dsfdsfdsfds 16F37E59FE494AC9B17A2340387335EF 119
but when i code
select row_.*, rownum rownum_ from (select topic0_.id as id6_, topic0_.title as title6_, topic0_.publish_author_id as publish3_6_, topic0_.reply_number as reply4_6_, topic0_.read_number as read5_6_, topic0_.publish_author_name as publish6_6_, topic0_.publish_time as publish7_6_, topic0_.last_reply_time as last8_6_, topic0_.last_reply_name as last9_6_, topic0_.main_text as main10_6_, topic0_.FORUM_ID as FORUM11_6_ from topic topic0_ where topic0_.FORUM_ID='16F37E59FE494AC9B17A2340387335EF' order by case when topic0_.last_reply_time is not null then topic0_.last_reply_time else topic0_.publish_time end desc) row_ where rownum <=6;
the result is
ID6_ TITLE6_ PUBLISH3_6_ REPLY4_6_ READ5_6_ PUBLISH6_6_ PUBLISH7_6_ LAST8_6_ LAST9_6_ MAIN10_6_ FORUM11_6_ ROWNUM_
1 402840713e108ea4013e1090c95c0001 trytr 2 2 0 ss 2013-4-16 9:58:44 2013-4-16 9:59:21 ss fdsfds 16F37E59FE494AC9B17A2340387335EF 1
2 402840713e108ea4013e1090127e0000 trytr 2 0 0 ss 2013-4-16 9:57:57 ytrytr 16F37E59FE494AC9B17A2340387335EF 2
3 402840713e0d3616013e0d3618c20000 cde0 2 0 0 ss 2013-4-15 18:20:49 abc0 16F37E59FE494AC9B17A2340387335EF 3
4 402840713e0d3616013e0d3618ce0003 cde3 2 0 0 ss 2013-4-15 18:20:49 abc3 16F37E59FE494AC9B17A2340387335EF 4
5 402840713e0d3616013e0d3618ce0002 cde2 2 0 0 ss 2013-4-15 18:20:49 abc2 16F37E59FE494AC9B17A2340387335EF 5
6 402840713e0d3616013e0d3618cd0001 cde1 2 0 0 ss 2013-4-15 18:20:49 abc1 16F37E59FE494AC9B17A2340387335EF 6
why ? i want the result is:
ID6_ TITLE6_ PUBLISH3_6_ REPLY4_6_ READ5_6_ PUBLISH6_6_ PUBLISH7_6_ LAST8_6_ LAST9_6_ MAIN10_6_ FORUM11_6_ ROWNUM_
1 402840713e108ea4013e1090c95c0001 trytr 2 2 0 ss 2013-4-16 9:58:44 2013-4-16 9:59:21 ss fdsfds 16F37E59FE494AC9B17A2340387335EF 1
2 402840713e108ea4013e1090127e0000 trytr 2 0 0 ss 2013-4-16 9:57:57 ytrytr 16F37E59FE494AC9B17A2340387335EF 2
3 402840713e0d3616013e0d3618c20000 cde0 2 0 0 ss 2013-4-15 18:20:49 abc0 16F37E59FE494AC9B17A2340387335EF 3
4 402840713e0d3616013e0d3618da0063 cde99 2 0 0 ss 2013-4-15 18:20:49 abc99 16F37E59FE494AC9B17A2340387335EF 4
5 402840713e0d3616013e0d3618da0062 cde98 2 0 0 ss 2013-4-15 18:20:49 abc98 16F37E59FE494AC9B17A2340387335EF 5
6 402840713e0d3616013e0d3618da0061 cde97 2 0 0 ss 2013-4-15 18:20:49 abc97 16F37E59FE494AC9B17A2340387335EF 6
If somebody could explain to me I'd be most grateful.
In your first query you have:
select row_.*, rownum rownum_ from (select ... order by ...) row_;
In the second you have:
select row_.*, rownum rownum_ from (select ... order by ...) row_
where rownum <= 6;
rownum is a pseudo-column that is generated as the last step in the query, over the result set that has already been produced. The where rownum <= 6 is being applied against the results of the inner select, but at that point in the outer select you have no explicit order by clause so the order the rownum will be assigned isn't guaranteed.
You could either repeat the order by clause in the outer query, which would make it even more unpleasant to deal with, or more simply move the rownum inside the inner select:
select * from (select ..., rownum rownum_ from ... order by ...)
where rownum_ <= 6;
It's unclear if the results form the your first query are in the correct order anyway; probably, but again probably not guaranteed, so you can also order that to make sure:
select * from (select ..., rownum rownum_ from ... order by ...)
where rownum_ <= 6
order by rownum_;
(Another approach would be to use an analytic function like dense_rank() against the case you're using in the order by, and then use that in the outer where to restrict the number of rows, but that's getting a bit away from the question...)
Oracle doesn't guarantee the same order of rows while executing the same query without order by clause.
The documentation says: ROWNUM is assigned by Oracle to show "the order in which Oracle selects the row from a table or set of joined rows". That is, before the result set is sorted. Find out more.
So if you want to guarantee that the top-n rows are always same rows for a given result set you need to pre-sort it.
select t2.* from
( select t1.*, rownum as rownum_ from
( select t.* from t order by t.whatever ) t1
)
where rownum_ <= 6
;
There are other ways of solving top-n questions - such as using RANK or ROW_NUMBER - but they all rely on an inner query. Here is the above solution done with ROW_NUMBER() instead.
select t1.* from
( select t.*
, row_number() over ( order by t.whatever ) as rownum_
from t ) t1
where rownum_ <= 6
;
Related
This question already has answers here:
bash: shortest way to get n-th column of output
(8 answers)
Closed 4 years ago.
I would like to extract column number 8 from the following table using shell (ash):
0xd024 2 0 32 20 3 0 1 0 2 1384 1692 -61 27694088
0xd028 0 1 5 11 1 0 46 0 0 301 187 -74 27689154
0xd02c 0 0 35 14 1 0 21 0 0 257 250 -80 27689410
0xd030 1 1 15 13 1 0 38 0 0 176 106 -91 27689666
0xd034 1 1 50 20 1 0 8 0 0 790 283 -71 27689980
0xd038 0 0 0 3 4 0 89 0 0 1633 390 -90 27690291
0xd03c 0 0 8 3 3 0 82 0 0 1837 184 -95 27690603
0xd040 0 0 4 5 1 0 90 0 0 0 148 -97 27690915
0xd064 0 0 36 9 1 0 29 0 0 321 111 -74 27691227
0xd068 0 0 5 14 14 0 40 0 0 8066 2270 -85 27691539
0xd06c 1 1 39 19 1 0 15 0 0 1342 261 -74 27691850
0xd070 0 0 12 11 1 0 53 0 0 203 174 -73 27692162
0xd074 0 0 18 2 1 0 75 0 0 301 277 -94 27692474
How can I do that?
the following command "awk '{print $8}' file" works fine
I do not want to wait for Oracle DataDump expdb to finish writing to dump file.
So I start reading data from the moment it's created.
Then I write this data to another file.
It worked ok - file sizes are the same (the one that OracleDump created and the one my data monitoring script created).
But when I run cmp it shows difference in 27 bytes:
cmp -l ora.dmp monitor_10k_rows.dmp
3 263 154
4 201 131
5 174 173
6 103 75
48 64 70
58 0 340
64 0 1
65 0 104
66 0 110
541 60 61
545 60 61
552 60 61
559 60 61
20508 0 15
20509 0 157
20510 0 230
20526 0 10
20532 0 15
20533 0 225
20534 0 150
913437 0 226
913438 0 37
913454 0 10
913460 0 1
913461 0 104
913462 0 100
ls -al ora.dmp
-rw-r--r-- 1 oracle oinstall 999424 Jun 20 11:35 ora.dmp
python -c 'print 999424-913462'
85962
od ora.dmp -j 913461 -N 1
3370065 000100
3370066
od monitor_10k_rows.dmp -j 913461 -N 1
3370065 000000
3370066
Even if I extract more data the difference is still 27 bytes but different addresses/values:
cmp -l ora.dmp monitor_30k_rows.dmp
3 245 134
4 222 264
5 377 376
6 54 45
48 36 43
57 0 2
58 0 216
64 0 1
65 0 104
66 0 120
541 60 61
545 60 61
552 60 61
559 60 61
20508 0 50
20509 0 126
20510 0 173
20526 0 10
20532 0 50
20533 0 174
20534 0 120
2674717 0 226
2674718 0 47
2674734 0 10
2674740 0 1
2674741 0 104
2674742 0 110
Some writes are the same.
Is there a way know addresses of bytes which will differ?
ls -al ora.dmp
-rw-r--r-- 1 bicadmin bic 2760704 Jun 20 11:09 ora.dmp
python -c 'print 2760704-2674742'
85962
How can update my monitored copy after DataDump updated the original at adress 2674742 using Python for example?
Exact same thing happens if I use COMPRESSION=DATA_ONLY option.
Update: Figured how to sync bytes that differ between 2 files:
def patch_file(fn, diff):
for line in diff.split(os.linesep):
if line:
addr, to_octal, _ = line.strip().split()
with open(fn , 'r+b') as f:
f.seek(int(addr)-1)
f.write(chr(int (to_octal,8)))
diff="""
3 157 266
4 232 276
5 272 273
6 16 25
48 64 57
58 340 0
64 1 0
65 104 0
66 110 0
541 61 60
545 61 60
552 61 60
559 61 60
20508 15 0
20509 157 0
20510 230 0
20526 10 0
20532 15 0
20533 225 0
20534 150 0
913437 226 0
913438 37 0
913454 10 0
913460 1 0
913461 104 0
913462 100 0
"""
patch_file(f3,diff)
wrote a patch using Python:
addr=[3 , 4 , 5 , 6 , 48 , 58 , 64 , 65 , 66 , 541 , 545 , 552 , 559 , 20508 , 20509 , 20510 , 20526 , 20532 , 20533 , 20534 ]
last_range=[85987, 85986, 85970, 85964, 85963, 85962]
def get_bytes(addr):
out =[]
with open(f1 , 'r+b') as f:
for a in addr:
f.seek(a-1)
data= f.read(1)
hex= binascii.hexlify(data)
binary = int(hex, 16)
octa= oct(binary)
out.append((a,octa))
return out
def patch_file(fn, bytes_to_update):
with open(fn , 'r+b') as f:
for (a,to_octal) in bytes_to_update:
print (a,to_octal)
f.seek(int(a)-1)
f.write(chr(int (to_octal,8)))
if 1:
from_file=f1
fsize=os.stat(from_file).st_size
bytes_to_read = addr + [fsize-x for x in last_range]
bytes_to_update = get_bytes(bytes_to_read)
to_file =f3
patch_file(to_file,bytes_to_update)
The reason I do dmp file monitoring is because it cuts backup time in half.
Hello I have this input:
10579 5 2.0 5 100 0 20 0 80 0 20 0.72
10586 5 2.0 5 100 0 20 0 40 20 40 1.52
10856 4 3.2 4 100 0 26 0 69 30 0 0.89
11049 6 12.2 6 65 26 48 14 36 49 0 1.43
11041 2 26.0 2 70 37 20 8 43 47 0 1.34
11012 5 3.0 5 90 9 25 0 56 43 0 0.99
11041 5 3.0 5 9 25 0 56 43 0 0.99
11096 6 2.2 6 100 0 26 15 30 53 0 1.42
11194 1 28.0 1 93 6 51 0 3 96 0 0.22
11236 5 2.4 5 0 24 0 41 58 0 0.98
11981 1 10.0 1 50 18 15 0 9 0 90 0.44
12184 5 2.2 5 100 0 22 18 0 54 27 1.44
12482 4 2.5 4 100 0 20 20 0 80 0 0.72
12627 5 2.2 5 100 0 22 18 0 81 0 0.68
I want to remove lines when the column 5 is smaller than 85. I can do that with awk (awk '$5 > 85') but I want to keep lines when $5 is empty (line 7 and 10). So my output will be like this:
10579 5 2.0 5 100 0 20 0 80 0 20 0.72
10586 5 2.0 5 100 0 20 0 40 20 40 1.52
10579 5 2.0 5 100 0 20 0 80 0 20 0.72
10586 5 2.0 5 100 0 20 0 40 20 40 1.52
10856 4 3.2 4 100 0 26 0 69 30 0 0.89
11012 5 3.0 5 90 9 25 0 56 43 0 0.99
11041 5 3.0 5 9 25 0 56 43 0 0.99
11096 6 2.2 6 100 0 26 15 30 53 0 1.42
11194 1 28.0 1 93 6 51 0 3 96 0 0.22
11236 5 2.4 5 0 24 0 41 58 0 0.78
12184 5 2.2 5 100 0 22 18 0 54 27 1.44
12482 4 2.5 4 100 0 20 20 0 80 0 0.72
12627 5 2.2 5 100 0 22 18 0 81 0 0.68
awk '$5 > 85' is removing also those line. Any help? Thanks
you have to set your field delimiter to a single space, otherwise awk wouldn't know which field is missing
$ awk -F' ' '$5>85' file
10579 5 2.0 5 100 0 20 0 80 0 20 0.72
10586 5 2.0 5 100 0 20 0 40 20 40 1.52
10856 4 3.2 4 100 0 26 0 69 30 0 0.89
11012 5 3.0 5 90 9 25 0 56 43 0 0.99
11096 6 2.2 6 100 0 26 15 30 53 0 1.42
11194 1 28.0 1 93 6 51 0 3 96 0 0.22
12184 5 2.2 5 100 0 22 18 0 54 27 1.44
12482 4 2.5 4 100 0 20 20 0 80 0 0.72
12627 5 2.2 5 100 0 22 18 0 81 0 0.68
I have a matrix that is 50x2. But column 2 has different amount of entries. How can I make a box plot where the x axis is position and the y axis are the different counts? Ideally, I'd like to take the absolute value of the counts. Thanks in advance!
> mat.count[1:50,]
position count
1 136873135 0
2 136873136 0
3 136873137 0
4 136873138 0
5 136873139 0
6 136873140 -15
7 136873141 0
8 136873142 0
9 136873143 0
10 136873144 0
11 136873145 0
12 136873146 0
13 136873147 0
14 136873148 0
15 136873149 0
16 136873150 0
17 136873151 0
18 136873152 0
19 136873153 0
20 136873154 0
21 136873155 0
22 136873156 0
23 136873157 0
24 136873158 0
25 136873159 0
26 136873160 0
27 136873161 0
28 136873162 0
29 136873163 0
30 136873164 0
31 136873165 0
32 136873166 0
33 136873167 0
34 136873168 -1
35 136873169 0
36 136873170 0
37 136873171 0
38 136873172 0
39 136873173 -70
40 136873174 -66
41 136873175 -73,-1,-1,-1,-73,-1
42 136873176 -52
43 136873177 0
44 136873178 0
45 136873179 -66,-1
46 136873180 -1
47 136873181 0
48 136873182 -68,-75
49 136873183 -67,-67
50 136873184 -60,-56,-56
I have this table as a result from another query
STATUS R1 R2 R3 R4 R5 R6 R7 R8 R9
----------------------------------------------------
ACCEPTED 322 241 278 473 575 595 567 449 605
ADECUACIONES 0 0 0 0 2 0 1 0 50
AET 0 0 2 0 0 0 0 0 11
EXECUTED 0 80 1 18 9 57 34 30 20
IN PROCESS 0 0 0 0 0 4 25 2 112
FREQ 0 55 2 76 25 117 7 73 48
INSTALL 1 4 1 10 5 14 2 13 62
WO INSTALL 9 2 51 24 143 17 15 59 16
WOT VL 0 1 0 0 1 0 0 0 0
OTHER 22 7 20 28 44 30 6 6 109
PROG 1 0 1 0 0 2 3 0 0
PTE PROG 0 5 0 0 0 0 3 19 93
TMX 0 0 0 28 4 8 11 3 14
PROJ 0 1 12 26 13 8 0 2 4
What I expect to have is this
STATUS R1 R2 R3 R4 R5 R6 R7 R8 R9 TOTAL
----------------------------------------------------------
ACCEPTED 322 241 278 473 575 595 567 449 605 4105
ADECUACIONES 0 0 0 0 2 0 1 0 50 53
AET 0 0 2 0 0 0 0 0 11 13
EXECUTED 0 80 1 18 9 57 34 30 20 249
IN PROCESS 0 0 0 0 0 4 25 2 112 143
FREQ 0 55 2 76 25 117 7 73 48 403
INSTALL 1 4 1 10 5 14 2 13 62 112
WO INSTALL 9 2 51 24 143 17 15 59 16 336
WOT VL 0 1 0 0 1 0 0 0 0 2
OTHER 22 7 20 28 44 30 6 6 109 272
PROG 1 0 1 0 0 2 3 0 0 7
PTE PROG 0 5 0 0 0 0 3 19 93 120
TMX 0 0 0 28 4 8 11 3 14 68
PROJ 0 1 12 26 13 8 0 2 4 66
TOTAL 355 396 368 683 821 852 674 656 1144 5949
I've been playing with grouping() and rollup(), but I always get duplicated rows and unwanted null values.
If you have problems, grouping_id function will help you.
(You can select grouping_id(col), but also grouping_id(col1, col2, col3, etc..))
But your case is simpler.
It is like:
drop table fg_test_group;
create table fg_test_group (a number, b number, c number, d number);
insert into fg_test_group values (1, 2, 3, 4);
insert into fg_test_group values (2, 2, 3, 4);
insert into fg_test_group values (3, 2, 3, 4);
select nvl(to_char(a), 'total') as a , sum(b), sum(c), sum(d), grouping_id(a)
from fg_test_group
group by rollup (a)
;
where a is Status in your case.
CREATE TABLE TEST1 (STATUS VARCHAR2(10), R1 NUMBER, R2 NUMBER, R3 NUMBER);
INSERT INTO TEST1 VALUES ('ACCEPTED', 322,241,278);
INSERT INTO TEST1 VALUES ('EXECUTED', 0, 80, 1);
INSERT INTO TEST1 VALUES ('FREQ', 0, 55, 2);
COMMIT;
select NVL(TO_CHAR(STATUS), 'total') as STATUS ,SUM(R1) R1, SUM(R2) R2 , SUM(R3) R3, SUM(R1+R2+R3)
from TEST1
group by rollup (STATUS)
;
STATUS R1 R2 R3 SUM(R1+R2+R3)
ACCEPTED 322 241 278 841
EXECUTED 0 80 1 81
FREQ 0 55 2 57
total 322 376 281 979