with t1 as (select 1 id, '222' se union all
select 2, '222,333' union all
select 3, '333,222' union all
select 4, '333,111,222')
select *
from t1
where find_in_set( '222', se) and find_in_set( '333', se)
with t1 as (select 1 id, '222' se union all
select 2, '222,333' union all
select 3, '333,222' union all
select 4, '333,111,222')
select *
from t1
where find_in_set( '222', se) and find_in_set( '333', se)
having abs(find_in_set( '222', se)-find_in_set( '333', se)) = 1
select
case when t1.attr_type = 1 and t1.value_int = 20 then t1.value_int end y,
case when t1.attr_type = 2 and t1.value_int = 4 then t1.value_int end m,
case when t1.attr_type = 3 and t1.value_int = 4 then t1.value_int end d,
case when t1.attr_type = 4 and t1.value_string = 'google' then t1.value_string end utm_source,
k.value_int kind_int,
i.count cnt
from stat_item_attrs k
left join stat_item i on i.id = k.item_id
join stat_item_attrs t1 on t1.item_id = k.item_id and t1.attr_type in (1/*y*/,2/*m*/,3/*d*/4/*utm_source*/) and (t1.value_int in (20, 4 /*20-04-04*/) or t1.value_string = 'google')
where
k.attr_type = 0/*kind*/ and k.value_int in(0,1)/*hosts,leads*/
SELECT * FROM `table`
WHERE 1 = 1
and `column1` LIKE '%word1%'
and `column1` LIKE '%word2%'
and `column1` LIKE '%word3%'
and `column1` LIKE '%word4%'
and `column1` LIKE '%word5%'
select id,
name,
parent_id
from (select * from products
order by parent_id, id) products_sorted,
(select @pv := '2') initialisation
where find_in_set(parent_id, @pv)
and length(@pv := concat(@pv, ',', id))
select distinct
FIRST_VALUE(currency) OVER (PARTITION BY currency ORDER BY created_at desc) currency,
FIRST_VALUE(price) OVER (PARTITION BY currency ORDER BY created_at desc) price
from course
select *
from (SELECT `c`.*, row_number() OVER (partition by `c`.`articleId` order by `c`.`date` DESC ) rn
FROM comments AS `c` WHERE `c`.`articleId` IN (
'44',
'55',
'414',
'555',
'775'
) AND `c`.`approved` ='1' ORDER BY `c`.`date` DESC) t1
where rn <= 5;
SELECT * FROM production as t1
LEFT JOIN production_favorite as t2 ON t1.id = t2.product_id
WHERE t1.brand_id = 145 and t2.name = 'opisanie'
select af_id, sum(coalesce(amount_value,0))*0.1 sum_pair_10
from (
select
arur.af_id,
arur.r_w_uid,
lag(arur.r_w_uid,1,-1) over (partition by arur.af_id order by arur.r_w_uid) r_w_uid_1
,row_number() OVER (partition by arur.af_id order by arur.r_w_uid ) mod 2 pair_flag
from arur, u_af
where u_af.id = arur.af_id ) t1 left join orders o on (o.uid in (t1.r_w_uid,t1.r_w_uid_1) and o.status = 'Completed')
where pair_flag = 0
group by af_id
having count(distinct r_w_uid) > 5
select af_id, sum(coalesce(amount_value,0))*0.1 sum_pair_10
from (SELECT arur.af_id,
arur.r_w_uid,
@row_num := CASE WHEN @row_num_val = af_id THEN @row_num+1
WHEN (@row_num_val := af_id) IS NOT NULL THEN 1
END pair_flag,
@lag_r_w_uid := CASE WHEN (@row_num_val = af_id) and @row_num mod 2 = 1 THEN r_w_uid
else @lag_r_w_uid
END r_w_uid_1
FROM arur, u_af, (SELECT @row_num := null, @row_num_val := null, @lag_r_w_uid := null) AS x
where u_af.id = arur.af_id
ORDER BY af_id, r_w_uid ) t1 left join orders o on (o.uid in (t1.r_w_uid,t1.r_w_uid_1) and o.status = 'Completed')
where pair_flag mod 2 = 0
group by af_id
having count(distinct r_w_uid) > 5