<?php
$art = '(#КЛП1483П1)';
echo trim($art, ')(#');
echo PHP_EOL;
preg_match('/^\(#(.+)\)$/', $art, $m);
echo $m[1];
echo PHP_EOL;
echo substr($art, 2, -1);
echo PHP_EOL;
select 't1', phone from t1 where phone = '987654321'
union all select 't2', phone from t2 where phone = '987654321'
union all select 't3', phone from t3 where phone = '987654321'
WITH countries_links AS (
SELECT JSON_OBJECT('name', `name`, 'iso2', `iso2`, 'links', COUNT(`link_id`)) d
FROM `links`
JOIN `countries` ON `countries`.`iso2` = `links`.`country`
GROUP BY `name`, `iso2`
HAVING COUNT(`link_id`) > 0
) SELECT JSON_ARRAYAGG(d) FROM countries_links
select distinct t.id_user from T as t
where
t.year = 2023 and
not exists (select id_user from T tt where year = 2022 and tt.id_user = t.id_user);
-- LEFT JOIN
select distinct t.id_user
from T as t
left join T tt on tt.year = 2022 and tt.id_user = t.id_user
where t.year = 2023 and tt.id_user is null;
-- EXCEPT
select distinct t.id_user from T as t
where t.year = 2023
except
select distinct t.id_user from T as t
where t.year = 2022
;
create table users (
id integer primary key autoincrement,
mute_time int not null default 0
);
insert into products (product_id, name, variant, price)
select
coalesce (
min(case when name = 'мышь' then product_id end ),
coalesce(min(product_id), 0) + 1
) product_id
,'мышь', 'красная', 150
from products;
select 1, NEWID()
union select 2, NEWID()
union select 3, NEWID()
union select 4, NEWID()
union select 4, NEWID()
union select 6, NEWID()
union select 7, NEWID()
union select 8, NEWID()
union select 9, NEWID()
union select 10, NEWID();
SELECT * ....
EXCEPT
SELECT * ....;
CREATE PROCEDURE [dbo].[addTask]
@definition varchar(1000),
@userEmail varchar(30)
AS
BEGIN
IF (@userEmail is not null)
BEGIN
INSERT INTO Задача(Описание) VALUES (@definition)
INSERT INTO Реализация_задачи (ID_работника, ID_задачи)
SELECT ID_работника, SCOPE_IDENTITY()
FROM Работник WHERE Электронная_почта = @userEmail
END
END
GO
EXEC addTask @definition = 'New task', @userEmail = 'Employee@mail.com'
GO
SELECT EMPLOYER.EMP_NAME, DEPARTMENT.DEP_NAME, POSITION, SALARY
FROM SALARY
JOIN EMPLOYER ON EMPLOYER.EMP_ID = SALARY.EMP_ID
JOIN DEPARTMENT ON DEPARTMENT.DEP_ID = EMPLOYER.DEP_ID
WHERE PERIOD = 201905;
select * from tbl
where id_ref = 99 and delete = 0
order by id_carrier desc
limit 1;