
Алексей
20.02.2018
17:21:09
SELECT
`a`.`advert_id`,
`a`.`advert_num`,
`a`.`advert_name`,
`a`.`advert_link`,
`a`.`advert_rang`,
`a`.`city_city_id`,
`a`.`district_district_id`,
`a`.`microdistrict_microdistrict_id`,
`a`.`source_source_id`,
`a`.`type_type_id`,
`a`.`user_user_id`,
`a`.`advert_parse_date`,
`a`.`advert_what`,
`a`.`advert_archive`,
`a`.`advert_commtype`,
`a`.`advert_commtype` as commtype_name,
`a`.`advert_active`,
X(`a`.advert_coordinate) as 'X',
Y(`a`.advert_coordinate) as 'Y',
`c`.*,
`t`.*,
`t1`.*,
`t2`.*,
`t3`.*,
`t4`.*,
`t7`.*,
`t8`.*
FROM advert1 a
LEFT JOIN whats t1 ON t1.whats_id = a.advert_what
LEFT JOIN type t2 ON t2.type_id = a.type_type_id
LEFT JOIN source t3 ON t3.source_id = a.source_source_id
LEFT JOIN microdistrict t8 ON t8.microdistrict_id = a.microdistrict_microdistrict_id
LEFT JOIN district t4 ON t4.district_id = a.district_district_id
LEFT JOIN city t7 ON t7.city_id = a.city_city_id
LEFT JOIN cache_1 c ON (((((((`c`.`advert_id`=`a`.`advert_id` AND (IF(99 in(2, 3), true, `c`.`filter-spec` IN (2, 3) OR IF(0 in (2, 3), `c`.`filter-spec` is null, false)))) AND (IF('1' in (2) ,
TRUE,
IF('2' in (2),
`c`.`filter-floor`>1,
IF('3' in (2),
`c`.`filter-floor` < `c`.`floors`,
`c`.`filter-floor`>1 AND `c`.`filter-floor`<`c`.`floors`
)
)
))) AND (`c`.`filter-price` >= 100000)) AND (IF(1000000000=0,TRUE,`c`.`filter-price` <= 1000000000))) AND (`c`.`space` >= 100)) AND (IF(10000000=0, TRUE, `c`.`space` <= 10000000))) AND (lower (`c`.`address`) REGEXP CONCAT('.*(',REPLACE(lower('ромашек'),',','|'),').*')))
LEFT JOIN cache_1_text t ON (((`t`.`advert_id`=`a`.`advert_id` AND (lower(`t`.`advert_text`) REGEXP CONCAT('.*(',lower(REPLACE('продажа',',','|')),').*'))) AND (IF('on'='on',
(NOT (`t`.`advert_text` IS NULL) AND LENGTH(`t`.`advert_text`)>20),
IF('on'='off',
(`t`.`advert_text` IS NULL OR LENGTH(`t`.`advert_text`)<=20),
true
)
))) AND (IF('on'='on',
(NOT (`t`.`photos` IS NULL) AND (JSON_VALID(`t`.photos)=1 AND LENGTH(JSON_EXTRACT(`t`.photos,'$.photo'))>10)),
IF('on'='off',
((`t`.`photos` IS NULL) OR JSON_VALID(`t`.photos)=0 OR (JSON_VALID(`t`.photos)=1 AND LENGTH(JSON_EXTRACT(`t`.photos,'$.photo'))<10)),
true
)
)))
WHERE (((((true AND (`a`.`advert_what` IN(1))) AND (`a`.`microdistrict_microdistrict_id` IN (29, 32, 33, 35, 37, 38, 39))) AND (if('off'='off',
(`a`.`advert_archive` IS NULL) OR NOT(`a`.`advert_archive`)
, true))) AND (`a`.type_type_id = 1))) AND ((((((((`c`.`advert_id`=`a`.`advert_id` AND (IF(99 in(2, 3), true, `c`.`filter-spec` IN (2, 3) OR IF(0 in (2, 3), `c`.`filter-spec` is null, false)))) AND (IF('1' in (2) ,
TRUE,
IF('2' in (2),
`c`.`filter-floor`>1,
IF('3' in (2),
`c`.`filter-floor` < `c`.`floors`,
`c`.`filter-floor`>1 AND `c`.`filter-floor`<`c`.`floors`
)
)
))) AND (`c`.`filter-price` >= 100000)) AND (IF(1000000000=0,TRUE,`c`.`filter-price` <= 1000000000))) AND (`c`.`space` >= 100)) AND (IF(10000000=0, TRUE, `c`.`space` <= 10000000))) AND (lower (`c`.`address`) REGEXP CONCAT('.*(',REPLACE(lower('ромашек'),',','|'),').*')))) AND ((((`t`.`advert_id`=`a`.`advert_id` AND (lower(`t`.`advert_text`) REGEXP CONCAT('.*(',lower(REPLACE('продажа',',','|')),').*'))) AND (IF('on'='on',
(NOT (`t`.`advert_text` IS NULL) AND LENGTH(`t`.`advert_text`)>20),
IF('on'='off',
(`t`.`advert_text` IS NULL OR LENGTH(`t`.`advert_text`)<=20),
true
)
))) AND (IF('on'='on',
(NOT (`t`.`photos` IS NULL) AND (JSON_VALID(`t`.photos)=1 AND LENGTH(JSON_EXTRACT(`t`.photos,'$.photo'))>10)),
IF('on'='off',
((`t`.`photos` IS NULL) OR JSON_VALID(`t`.photos)=0 OR (JSON_VALID(`t`.photos)=1 AND LENGTH(JSON_EXTRACT(`t`.photos,'$.photo'))<10)),
true
)
)))) ORDER BY `a`.`advert_rang` DESC LIMIT 25 OFFSET 0
померимся