SELECT MAX(fieldname) FROM table;
SET @t = '528223,528224';
SELECT * FROM t
WHERE FIND_IN_SET (t.id, @t );
INSERT INTO aqf_news (
`title_az`, `date`, `short_text_az`, `full_text_az`, `category_id`, `gallery`, `gallery_narative_az`, `video1`, `show_slider`, `info_source`
) VALUES (
'test', NOW(), 'short_text_az', 'full_text_az', 'category_id', 'gallery', 'gallery_narative_az', 'video1', COALESCE(show_slider, 0), 'info_source'
)
UPDATE users
SET lastLogin = CURRENT_TIMESTAMP
WHERE email = 'test@mail.ru'
;
<?php
$str = '[contact-form-7 id="6274" title="Какой то текст с пробелами"]';
preg_match("/\[(\S+) (\S+) (.+)\]/im", $str, $matches);
var_export($matches);
$titlepage = explode( "\n" , $text);
$new_text = implode(PHP_EOL, array_slice($titlepage, 1));
echo $new_text;
echo preg_replace('/\A(.*)$/mi', '', $text);
select
* ,
case
when role = 'boss' then 3
when role = 'admin' then 2
else 1
end as weight
from gamers order by weight desc;
select *
from gamers
order by role = 'boss' desc, role = 'admin' desc;
<?php
$start = "10:00";
$stop = "02:00";
$current_time = time();
$start_time = strtotime($start);
$stop_time = strtotime($stop);
// if end time less then start add one day
if ($stop_time < $start_time) $stop_time += 60 * 60 * 24;
echo "$start_time < $current_time < $stop_time" . PHP_EOL;
if ($current_time < $start_time || $current_time > $stop_time) {
die('Closed');
}
echo 'Open';
select
age_hobbies.age,
age_hobbies.hobbies
from (
select age, hobbies, count(*) cnt
from user_hobbies
group by age, hobbies
) age_hobbies
join (
select age, max(cnt) maxcnt
from (
select age, hobbies, count(*) cnt
from user_hobbies
group by age, hobbies
) h group by age
) max_age_hobbies on
age_hobbies.age = max_age_hobbies.age and
age_hobbies.cnt = max_age_hobbies.maxcnt;
select
id,
title,
start,
end,
timediff(end, current_time) as remain_time
from lessons
where current_time between start and end
;
select *
from (
select age, hobbies, count(*) cnt
from user_hobbies
group by age, hobbies
) age_hobbies
join (
select age, max(cnt) maxcnt
from (
select age, hobbies, count(*) cnt
from user_hobbies
group by age, hobbies
) h group by age
) max_age_hobbies on
age_hobbies.age = max_age_hobbies.age and
age_hobbies.cnt = max_age_hobbies.maxcnt;
select
id,
Month,
LEAD(Month) OVER (ORDER BY Id) NextMonth
from Months;
$bd->Query("SELECT COUNT(*) FROM users_nykfageubf WHERE p = '$p' AND promo_new=1"))
$bd->Query("UPDATE users_nykfageubf SET balance=balance+10, promo_new = 0 WHERE p = '$p' AND promo_new=1");
$stmt = $bd->Query("SELECT 1 FROM users_nykfageubf WHERE p = '$p' AND promo_new=1 LIMIT 1");
if ($stmt->rowCount() > 0) {
...........
}
select *
from (
select
clients.*,
groups.title `group`,
row_number() over (partition by clients.id order by clients.id) rn -- order may be different
from clients
join `groups` on groups.id = clients.group_id
) client_groups
where rn < 10
update users_match
set usr2 = case
when usr1 = 1 then 5
when usr1 = 2 then 6
when usr1 = 3 then 7
else usr2
end;
select *
from orders
join (
select order_id, sum(price) paid
from transactions
group by order_id
) paiments on
paiments.order_id = orders.id and
(orders.price + orders.delivery_price) =< paiments.paid;
select *
from orders
left join (
select order_id, sum(price) paid
from transactions
group by order_id
) paiments on
paiments.order_id = orders.id
where (orders.price + orders.delivery_price) > coalecse(paiments.paid, 0);