select
box_id, max(name), max(another_name), "product",
sum(coalesce(incoming::numeric, 0)) "incoming",
sum(coalesce(output::numeric, 0)) "output",
sum(coalesce(incoming::numeric, 0)) - sum(coalesce(output::numeric, 0)) "balance"
from table1
group by product, box_id
order by box_id;
SELECT MAX(category_id) FROM stories
WHERE category = ANY(ARRAY['Тест', 'Тест2']);
echo json_encode($result, JSON_NUMERIC_CHECK);
SELECT
`messages`.`id` AS `messages_id`, `money_box`.`id` AS `money_box_id`
FROM `messages`,`money_box`;
select * from users
order by case
when v1 > 0 then v1
when v2 > 0 then v2
else v3
end desc;
if (preg_match('/^\+7 \(\d{3}\) \d{3}-\d{2}-\d{2}$/', $login_phone)) {
echo 'ok';
} else {
echo 'wrong number';
}
CREATE TABLE sportsmans(
id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
full_name VARCHAR(255),
email VARCHAR(255),
phone_number VARCHAR(11),
birthday date,
passport_number int(15),
average_rate int(11),
biography text,
video VARCHAR(255),
created_at datetime
);
preg_match_all('/<paramname>(.+)<\/paramname>/', $text, $matches); // <![CDATA[Модель]]>
preg_match_all('/<paramname><!\[CDATA\[(.+)\]\]><\/paramname>/', $text, $matches); //Модель
select n from unnest(array[1, 3, 5, 7]) n
left join test on n = id
where id is null;
select
row.user_id, count(*) matches_row_count
from users user_row
join users row on
(user_row.a_id = row.a_id) and
(user_row.b_id = row.b_id) and
(user_row.id != row.user_id)
where user_row.user_id = 1
group by row.user_id;