1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
|
7
|
CREATE PROC [dbo].[CF_GetMainCafePostList]
|
8
|
@lang_cd varchar(20),
|
9
|
@menu_id int,
|
10
|
@keyword NVARCHAR(100),
|
11
|
@orderby VARCHAR(20),
|
12
|
@cpage INT,
|
13
|
@pagesize INT
|
14
|
AS
|
15
|
|
16
|
DECLARE
|
17
|
@totcnt INT;
|
18
|
|
19
|
BEGIN
|
20
|
|
21
|
SET @totcnt = 0
|
22
|
|
23
|
|
24
|
if( @menu_id = 0 )
|
25
|
begin
|
26
|
|
27
|
SELECT
|
28
|
@totcnt = COUNT(*)
|
29
|
FROM [dbo].[CF_POSTS] p
|
30
|
INNER JOIN dbo.CF_CAFE_INFO c on c.cafe_id = p.cafe_id
|
31
|
WHERE c.CAFE_LANG = @lang_cd
|
32
|
AND c.IS_PUBLIC = 'Y'
|
33
|
AND c.IS_HOUSE <> 'Y'
|
34
|
AND c.STAT <> 9
|
35
|
AND p.STAT <> 9
|
36
|
AND p.POST_TITLE LIKE + '%' + @keyword + '%'
|
37
|
|
38
|
end
|
39
|
|
40
|
if( @menu_id = 0 )
|
41
|
begin
|
42
|
|
43
|
if( @orderby = 'forward' )
|
44
|
begin
|
45
|
|
46
|
SELECT
|
47
|
d.*,
|
48
|
isnull((select top 1 cafe_nick from dbo.CF_CAFE_MEMBERS where cafe_seq = d.cafe_seq and mem_no in (select top 1 mem_no from dbo.CF_MEMBER where mem_email = d.mem_email1)), d.mem_email1) as cafe_nick1,
|
49
|
isnull((select top 1 cafe_nick from dbo.CF_CAFE_MEMBERS where cafe_seq = d.cafe_seq and mem_no in (select top 1 mem_no from dbo.CF_MEMBER where mem_email = d.mem_email2)), d.mem_email2) as cafe_nick2,
|
50
|
isnull((select top 1 cafe_nick from dbo.CF_CAFE_MEMBERS where cafe_seq = d.cafe_seq and mem_no in (select top 1 mem_no from dbo.CF_MEMBER where mem_email = d.mem_email3)), d.mem_email3) as cafe_nick3
|
51
|
FROM (
|
52
|
SELECT
|
53
|
a.cafe_id,
|
54
|
a.cafe_seq,
|
55
|
a.cafe_name,
|
56
|
a.lang_cd,
|
57
|
a.region_cd,
|
58
|
a.TIMEZONE,
|
59
|
isnull(( select top 1 post_id from (select ROW_NUMBER() over(order by dt desc) as rownum, post_id from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 1 ), '') as post_id1,
|
60
|
isnull(( select top 1 post_title from (select ROW_NUMBER() over(order by dt desc) as rownum, post_title from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 1 ), '') as post_title1,
|
61
|
isnull(( select top 1 post_content from (select ROW_NUMBER() over(order by dt desc) as rownum, post_content from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 1 ), '') as post_content1,
|
62
|
isnull(( select top 1 writer from (select ROW_NUMBER() over(order by dt desc) as rownum, writer from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 1 ), '') as writer1,
|
63
|
isnull(( select top 1 mem_email from (select ROW_NUMBER() over(order by dt desc) as rownum, mem_email from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 1 ), '') as mem_email1,
|
64
|
isnull(( select top 1 dt from (select ROW_NUMBER() over(order by dt desc) as rownum, dt from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 1 ), '') as write_dt1,
|
65
|
isnull(( select top 1 post_id from (select ROW_NUMBER() over(order by dt desc) as rownum, post_id from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 2 ), '') as post_id2,
|
66
|
isnull(( select top 1 post_title from (select ROW_NUMBER() over(order by dt desc) as rownum, post_title from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 2 ), '') as post_title2,
|
67
|
isnull(( select top 1 post_content from (select ROW_NUMBER() over(order by dt desc) as rownum, post_content from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 2 ), '') as post_content2,
|
68
|
isnull(( select top 1 writer from (select ROW_NUMBER() over(order by dt desc) as rownum, writer from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 2 ), '') as writer2,
|
69
|
isnull(( select top 1 mem_email from (select ROW_NUMBER() over(order by dt desc) as rownum, mem_email from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 2 ), '') as mem_email2,
|
70
|
isnull(( select top 1 dt from (select ROW_NUMBER() over(order by dt desc) as rownum, dt from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 2 ), '') as write_dt2,
|
71
|
isnull(( select top 1 post_id from (select ROW_NUMBER() over(order by dt desc) as rownum, post_id from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 3 ), '') as post_id3,
|
72
|
isnull(( select top 1 post_title from (select ROW_NUMBER() over(order by dt desc) as rownum, post_title from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 3 ), '') as post_title3,
|
73
|
isnull(( select top 1 post_content from (select ROW_NUMBER() over(order by dt desc) as rownum, post_content from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 3 ), '') as post_content3,
|
74
|
isnull(( select top 1 writer from (select ROW_NUMBER() over(order by dt desc) as rownum, writer from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 3 ), '') as writer3,
|
75
|
isnull(( select top 1 mem_email from (select ROW_NUMBER() over(order by dt desc) as rownum, mem_email from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 3 ), '') as mem_email3,
|
76
|
isnull(( select top 1 dt from (select ROW_NUMBER() over(order by dt desc) as rownum, dt from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 3 ), '') as write_dt3,
|
77
|
(select count(*) from dbo.CF_CAFE_MEMBERS where cafe_seq in (select seq from dbo.CF_CAFE_INFO where cafe_id = a.CAFE_ID)) as mem_cnt,
|
78
|
(select top 1 file_name from dbo.CF_CAFE_FILES where cafe_id = a.CAFE_ID and file_type = 1 order by dt desc) as cafe_icon_file,
|
79
|
a.cafe_dt
|
80
|
FROM (
|
81
|
SELECT
|
82
|
p.*, c.DT as cafe_dt, c.seq as cafe_seq, c.timezone,
|
83
|
(select top 1 MENU_NAME from dbo.CF_CAFE_MENU where CAFE_ID = p.CAFE_ID and MENU_ID = p.MENU_ID) as menu_name,
|
84
|
(select top 1 CAFE_NAME from dbo.CF_CAFE_INFO where CAFE_ID = p.cafe_id) as cafe_name,
|
85
|
(select top 1 CAFE_DESC from dbo.CF_CAFE_INFO where CAFE_ID = p.cafe_id) as cafe_desc,
|
86
|
(select top 1 CAFE_LANG from dbo.CF_CAFE_INFO where CAFE_ID = p.cafe_id) as lang_cd,
|
87
|
(select top 1 REGION_CD from dbo.CF_CAFE_INFO where CAFE_ID = p.cafe_id) as region_cd
|
88
|
FROM [dbo].[CF_POSTS] p
|
89
|
INNER JOIN dbo.CF_CAFE_INFO c on c.cafe_id = p.cafe_id
|
90
|
WHERE c.CAFE_LANG = @lang_cd
|
91
|
AND c.IS_PUBLIC = 'Y'
|
92
|
AND c.IS_HOUSE <> 'Y'
|
93
|
AND c.STAT <> 9
|
94
|
AND p.STAT <> 9
|
95
|
AND p.POST_TITLE LIKE + '%' + @keyword + '%'
|
96
|
) a
|
97
|
GROUP BY
|
98
|
a.cafe_id, a.cafe_seq, a.cafe_name, a.lang_cd, a.region_cd, a.TIMEZONE, a.cafe_dt
|
99
|
) d
|
100
|
ORDER BY
|
101
|
d.cafe_dt ASC
|
102
|
OPTION (fast 3)
|
103
|
;
|
104
|
|
105
|
end
|
106
|
else if ( @orderby = 'users' )
|
107
|
begin
|
108
|
|
109
|
SELECT
|
110
|
d.*,
|
111
|
isnull((select top 1 cafe_nick from dbo.CF_CAFE_MEMBERS where cafe_seq = d.cafe_seq and mem_no in (select top 1 mem_no from dbo.CF_MEMBER where mem_email = d.mem_email1)), d.mem_email1) as cafe_nick1,
|
112
|
isnull((select top 1 cafe_nick from dbo.CF_CAFE_MEMBERS where cafe_seq = d.cafe_seq and mem_no in (select top 1 mem_no from dbo.CF_MEMBER where mem_email = d.mem_email2)), d.mem_email2) as cafe_nick2,
|
113
|
isnull((select top 1 cafe_nick from dbo.CF_CAFE_MEMBERS where cafe_seq = d.cafe_seq and mem_no in (select top 1 mem_no from dbo.CF_MEMBER where mem_email = d.mem_email3)), d.mem_email3) as cafe_nick3
|
114
|
FROM (
|
115
|
SELECT
|
116
|
a.cafe_id,
|
117
|
a.cafe_seq,
|
118
|
a.cafe_name,
|
119
|
a.lang_cd,
|
120
|
a.region_cd,
|
121
|
a.TIMEZONE,
|
122
|
isnull(( select top 1 post_id from (select ROW_NUMBER() over(order by dt desc) as rownum, post_id from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 1 ), '') as post_id1,
|
123
|
isnull(( select top 1 post_title from (select ROW_NUMBER() over(order by dt desc) as rownum, post_title from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 1 ), '') as post_title1,
|
124
|
isnull(( select top 1 post_content from (select ROW_NUMBER() over(order by dt desc) as rownum, post_content from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 1 ), '') as post_content1,
|
125
|
isnull(( select top 1 writer from (select ROW_NUMBER() over(order by dt desc) as rownum, writer from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 1 ), '') as writer1,
|
126
|
isnull(( select top 1 mem_email from (select ROW_NUMBER() over(order by dt desc) as rownum, mem_email from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 1 ), '') as mem_email1,
|
127
|
isnull(( select top 1 dt from (select ROW_NUMBER() over(order by dt desc) as rownum, dt from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 1 ), '') as write_dt1,
|
128
|
isnull(( select top 1 post_id from (select ROW_NUMBER() over(order by dt desc) as rownum, post_id from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 2 ), '') as post_id2,
|
129
|
isnull(( select top 1 post_title from (select ROW_NUMBER() over(order by dt desc) as rownum, post_title from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 2 ), '') as post_title2,
|
130
|
isnull(( select top 1 post_content from (select ROW_NUMBER() over(order by dt desc) as rownum, post_content from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 2 ), '') as post_content2,
|
131
|
isnull(( select top 1 writer from (select ROW_NUMBER() over(order by dt desc) as rownum, writer from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 2 ), '') as writer2,
|
132
|
isnull(( select top 1 mem_email from (select ROW_NUMBER() over(order by dt desc) as rownum, mem_email from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 2 ), '') as mem_email2,
|
133
|
isnull(( select top 1 dt from (select ROW_NUMBER() over(order by dt desc) as rownum, dt from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 2 ), '') as write_dt2,
|
134
|
isnull(( select top 1 post_id from (select ROW_NUMBER() over(order by dt desc) as rownum, post_id from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 3 ), '') as post_id3,
|
135
|
isnull(( select top 1 post_title from (select ROW_NUMBER() over(order by dt desc) as rownum, post_title from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 3 ), '') as post_title3,
|
136
|
isnull(( select top 1 post_content from (select ROW_NUMBER() over(order by dt desc) as rownum, post_content from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 3 ), '') as post_content3,
|
137
|
isnull(( select top 1 writer from (select ROW_NUMBER() over(order by dt desc) as rownum, writer from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 3 ), '') as writer3,
|
138
|
isnull(( select top 1 mem_email from (select ROW_NUMBER() over(order by dt desc) as rownum, mem_email from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 3 ), '') as mem_email3,
|
139
|
isnull(( select top 1 dt from (select ROW_NUMBER() over(order by dt desc) as rownum, dt from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 3 ), '') as write_dt3,
|
140
|
(select count(*) from dbo.CF_CAFE_MEMBERS where cafe_seq in (select seq from dbo.CF_CAFE_INFO where cafe_id = a.CAFE_ID)) as mem_cnt,
|
141
|
(select top 1 file_name from dbo.CF_CAFE_FILES where cafe_id = a.CAFE_ID and file_type = 1 order by dt desc) as cafe_icon_file,
|
142
|
a.cafe_dt
|
143
|
FROM (
|
144
|
SELECT
|
145
|
p.*, c.DT as cafe_dt, c.seq as cafe_seq, c.timezone,
|
146
|
(select top 1 MENU_NAME from dbo.CF_CAFE_MENU where CAFE_ID = p.CAFE_ID and MENU_ID = p.MENU_ID) as menu_name,
|
147
|
(select top 1 CAFE_NAME from dbo.CF_CAFE_INFO where CAFE_ID = p.cafe_id) as cafe_name,
|
148
|
(select top 1 CAFE_DESC from dbo.CF_CAFE_INFO where CAFE_ID = p.cafe_id) as cafe_desc,
|
149
|
(select top 1 CAFE_LANG from dbo.CF_CAFE_INFO where CAFE_ID = p.cafe_id) as lang_cd,
|
150
|
(select top 1 REGION_CD from dbo.CF_CAFE_INFO where CAFE_ID = p.cafe_id) as region_cd
|
151
|
FROM [dbo].[CF_POSTS] p
|
152
|
INNER JOIN dbo.CF_CAFE_INFO c on c.cafe_id = p.cafe_id
|
153
|
WHERE c.CAFE_LANG = @lang_cd
|
154
|
AND c.IS_PUBLIC = 'Y'
|
155
|
AND c.IS_HOUSE <> 'Y'
|
156
|
AND c.STAT <> 9
|
157
|
AND p.STAT <> 9
|
158
|
AND p.POST_TITLE LIKE + '%' + @keyword + '%'
|
159
|
) a
|
160
|
GROUP BY
|
161
|
a.cafe_id, a.cafe_seq, a.cafe_name, a.lang_cd, a.region_cd, a.TIMEZONE, a.cafe_dt
|
162
|
) d
|
163
|
ORDER BY
|
164
|
d.mem_cnt DESC
|
165
|
OPTION (fast 3)
|
166
|
;
|
167
|
|
168
|
end
|
169
|
else
|
170
|
begin
|
171
|
|
172
|
SELECT
|
173
|
d.*,
|
174
|
isnull((select top 1 cafe_nick from dbo.CF_CAFE_MEMBERS where cafe_seq = d.cafe_seq and mem_no in (select top 1 mem_no from dbo.CF_MEMBER where mem_email = d.mem_email1)), d.mem_email1) as cafe_nick1,
|
175
|
isnull((select top 1 cafe_nick from dbo.CF_CAFE_MEMBERS where cafe_seq = d.cafe_seq and mem_no in (select top 1 mem_no from dbo.CF_MEMBER where mem_email = d.mem_email2)), d.mem_email2) as cafe_nick2,
|
176
|
isnull((select top 1 cafe_nick from dbo.CF_CAFE_MEMBERS where cafe_seq = d.cafe_seq and mem_no in (select top 1 mem_no from dbo.CF_MEMBER where mem_email = d.mem_email3)), d.mem_email3) as cafe_nick3
|
177
|
FROM (
|
178
|
SELECT
|
179
|
a.cafe_id,
|
180
|
a.cafe_seq,
|
181
|
a.cafe_name,
|
182
|
a.lang_cd,
|
183
|
a.region_cd,
|
184
|
a.TIMEZONE,
|
185
|
isnull(( select top 1 post_id from (select ROW_NUMBER() over(order by dt desc) as rownum, post_id from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 1 ), '') as post_id1,
|
186
|
isnull(( select top 1 post_title from (select ROW_NUMBER() over(order by dt desc) as rownum, post_title from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 1 ), '') as post_title1,
|
187
|
isnull(( select top 1 post_content from (select ROW_NUMBER() over(order by dt desc) as rownum, post_content from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 1 ), '') as post_content1,
|
188
|
isnull(( select top 1 writer from (select ROW_NUMBER() over(order by dt desc) as rownum, writer from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 1 ), '') as writer1,
|
189
|
isnull(( select top 1 mem_email from (select ROW_NUMBER() over(order by dt desc) as rownum, mem_email from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 1 ), '') as mem_email1,
|
190
|
isnull(( select top 1 dt from (select ROW_NUMBER() over(order by dt desc) as rownum, dt from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 1 ), '') as write_dt1,
|
191
|
isnull(( select top 1 post_id from (select ROW_NUMBER() over(order by dt desc) as rownum, post_id from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 2 ), '') as post_id2,
|
192
|
isnull(( select top 1 post_title from (select ROW_NUMBER() over(order by dt desc) as rownum, post_title from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 2 ), '') as post_title2,
|
193
|
isnull(( select top 1 post_content from (select ROW_NUMBER() over(order by dt desc) as rownum, post_content from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 2 ), '') as post_content2,
|
194
|
isnull(( select top 1 writer from (select ROW_NUMBER() over(order by dt desc) as rownum, writer from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 2 ), '') as writer2,
|
195
|
isnull(( select top 1 mem_email from (select ROW_NUMBER() over(order by dt desc) as rownum, mem_email from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 2 ), '') as mem_email2,
|
196
|
isnull(( select top 1 dt from (select ROW_NUMBER() over(order by dt desc) as rownum, dt from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 2 ), '') as write_dt2,
|
197
|
isnull(( select top 1 post_id from (select ROW_NUMBER() over(order by dt desc) as rownum, post_id from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 3 ), '') as post_id3,
|
198
|
isnull(( select top 1 post_title from (select ROW_NUMBER() over(order by dt desc) as rownum, post_title from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 3 ), '') as post_title3,
|
199
|
isnull(( select top 1 post_content from (select ROW_NUMBER() over(order by dt desc) as rownum, post_content from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 3 ), '') as post_content3,
|
200
|
isnull(( select top 1 writer from (select ROW_NUMBER() over(order by dt desc) as rownum, writer from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 3 ), '') as writer3,
|
201
|
isnull(( select top 1 mem_email from (select ROW_NUMBER() over(order by dt desc) as rownum, mem_email from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 3 ), '') as mem_email3,
|
202
|
isnull(( select top 1 dt from (select ROW_NUMBER() over(order by dt desc) as rownum, dt from dbo.CF_POSTS where cafe_id = a.cafe_id and stat <> 9 and IS_PUBLIC = 'Y') t where rownum = 3 ), '') as write_dt3,
|
203
|
(select count(*) from dbo.CF_CAFE_MEMBERS where cafe_seq in (select seq from dbo.CF_CAFE_INFO where cafe_id = a.CAFE_ID)) as mem_cnt,
|
204
|
(select top 1 file_name from dbo.CF_CAFE_FILES where cafe_id = a.CAFE_ID and file_type = 1 order by dt desc) as cafe_icon_file,
|
205
|
a.cafe_dt
|
206
|
FROM (
|
207
|
SELECT
|
208
|
p.*, c.DT as cafe_dt, c.seq as cafe_seq, c.timezone,
|
209
|
(select top 1 MENU_NAME from dbo.CF_CAFE_MENU where CAFE_ID = p.CAFE_ID and MENU_ID = p.MENU_ID) as menu_name,
|
210
|
(select top 1 CAFE_NAME from dbo.CF_CAFE_INFO where CAFE_ID = p.cafe_id) as cafe_name,
|
211
|
(select top 1 CAFE_DESC from dbo.CF_CAFE_INFO where CAFE_ID = p.cafe_id) as cafe_desc,
|
212
|
(select top 1 CAFE_LANG from dbo.CF_CAFE_INFO where CAFE_ID = p.cafe_id) as lang_cd,
|
213
|
(select top 1 REGION_CD from dbo.CF_CAFE_INFO where CAFE_ID = p.cafe_id) as region_cd
|
214
|
FROM [dbo].[CF_POSTS] p
|
215
|
INNER JOIN dbo.CF_CAFE_INFO c on c.cafe_id = p.cafe_id
|
216
|
WHERE c.CAFE_LANG = @lang_cd
|
217
|
AND c.IS_PUBLIC = 'Y'
|
218
|
AND c.IS_HOUSE <> 'Y'
|
219
|
AND c.STAT <> 9
|
220
|
AND p.STAT <> 9
|
221
|
AND p.POST_TITLE LIKE + '%' + @keyword + '%'
|
222
|
) a
|
223
|
GROUP BY
|
224
|
a.cafe_id, a.cafe_seq, a.cafe_name, a.lang_cd, a.region_cd, a.TIMEZONE, a.cafe_dt
|
225
|
) d
|
226
|
ORDER BY
|
227
|
d.cafe_dt DESC
|
228
|
OPTION (fast 3)
|
229
|
;
|
230
|
|
231
|
end
|
232
|
|
233
|
end
|
234
|
|
235
|
print @totcnt;
|
236
|
RETURN @totcnt;
|
237
|
|
238
|
END
|
239
|
|
240
|
|
241
|
GO
|
242
|
|
243
|
|