SELECT t1.*
FROM primary_tbl t1
LEFT JOIN second_tbl t2 ON t2.pid=t1.id
WHERE t2.pid IS NULL
AND t1.key='file_name'
SELECT t.value, count(*) as users_count
FROM users u
JOIN (
SELECT d1.text as value, d1.user_id FROM data1 d1
UNION
SELECT d2.name as value, d2.user_id FROM data2 d2
) t on t.user_id = u.id
GROUP BY t.value
ORDER BY users_count DESC
SELECT `zadachi`.id AS id_zadacha,`zadachi`.*,`users`.*
FROM `zadachi`
INNER JOIN `users` ON `users`.id_1c = `zadachi`.autor
WHERE `zadachi`.komy = '$id' OR (`zadachi`.autor = '$id' AND `zadachi`.komy = '$id')
ORDER BY `zadachi`.id DESC
а: Группа новых задач...
б: Группа просроченных задач...
в: Группа поставленных задач кому то...
SELECT 'NEW' as group, .... FROM ...
UNION ALL
SELECT 'EXPIRED' as group, ... FROM ...
UNION ALL
SELECT 'OTHER' as group, ... FROM ...
SELECT * FROM (
SELECT ....... ROW_NUMBER() OVER (PARTITION BY posts.idRecordPost ORDER posts.datePost DESC) row_num
FROM .....
....
WHERE posts.idRecordPost IN (83, 91)
) t
WHERE t.row_num = 1
Catchable fatal error: Object of class waDbResultSelect could not be converted to string in
объект класса waDbResultSelect не может быть преобразован в строку
$n = $model -> query("SELECT * FROM `w3m_404urls` WHERE `url`= '$rqul'")
$n = $model -> query("SELECT * FROM `w3m_404urls` WHERE `url`= '$rqul'")->count();
if ($n > 0 ) {
// UPDATE
} else {
// INSERT
}
update tbl as t
inner join (
select 1 id, 'Один' text union
select 2 , 'Два' union
select 3 , 'Три' union
select 4 , 'Четыре'
) as tt on t.id = tt.id
set t.text = tt.text
;
update tbl as t
left join (
select 1 id, 'Один' text union
select 2 , 'Два' union
select 3 , 'Три' union
select 4 , 'Четыре'
) as tt on t.id = tt.id
set t.text = coalesce(tt.text, 'Другое значение')
;
set @i = 0;
update `grey_csgo_gifts_list`
set id = @i := @i + 1;
alter table `grey_csgo_gifts_list` modify `id` int(11) auto_increment primary key;
SELECT *
FROM tbl
WHERE replace(replace(replace(replace(name, '.', ''), '/', ''), '-', ''), ' ', '') = '10075153123А310РR';
SELECT *
FROM tbl
WHERE REGEXP_REPLACE(name, '[.\/-[:space:]]', '') = '10075153123А310РR';
select
replace(
text
,CONCAT('</table>', CHAR(10), CHAR(10),'</li>',CHAR(10),'</ul>')
, '</table>'
) as text
from tbl;
set @a = CONCAT('</table>', CHAR(10), CHAR(10),'</li>',CHAR(10),'</ul>');
update tbl
set text = replace(text, @a, '</table>');
</table>
или в тэгах есть побельные символы (пробел, табуляция и пр.) и/или "белые пробелы".(но нам то это неизвестно, данные у ВАС)
update tbl
set text = REGEXP_REPLACE(
text
,'<[[:blank:][:space:]]*\/table>[[:blank:][:space:]]+<[[:blank:][:space:]]*\/li>[[:blank:][:space:]]+<[[:blank:][:space:]]*\/ul>[[:blank:][:space:]]*'
,'</table>'
)
SELECT * FROM
(SELECT user_id FROM tbl GROUP BY user_id) u,
(SELECT 1 as mode UNION SELECT 2) m
;
SELECT t2.user_id, t2.mode, SUM(COALESCE(f1,0)) as f1, SUM(COALESCE(f2,0)) as f2
FROM tbl t1
RIGHT JOIN (
SELECT * FROM
(SELECT user_id FROM tbl GROUP BY user_id) u,
(SELECT 1 as mode UNION SELECT 2) m
) t2 ON t2.user_id = t1.user_id AND t2.mode = t1.mode
GROUP BY t2.user_id, t2.mode
ORDER BY t2.user_id, t2.mode
;
(SELECT user_id FROM tbl GROUP BY user_id) u1
, а к таблице user закроссить (SELECT 1 as mode UNION SELECT 2) m
и залефтджойнить подопытную таблицу.SELECT u.user_id, u.name, m.mode, SUM(COALESCE(f1,0)) as f1, SUM(COALESCE(f2,0)) as f2
FROM
users u
CROSS JOIN (SELECT 1 as mode UNION SELECT 2) m
LEFT JOIN tbl t ON u.user_id = t.user_id AND m.mode = t.mode
GROUP BY u.user_id, u.name, m.mode
;
SELECT
`ID`
, `post_title`
, pv30.cnt_month
, COALESCE(pv7.cnt_week, 0) cnt_week
, COALESCE(pv1.cnt_day, 0) cnt_day
FROM `wp_posts` AS p
INNER JOIN (
SELECT id, count(id) cnt_month
FROM `wp_post_views` pv
WHERE pv.time >= CURDATE() - INTERVAL 30 DAY
GROUP BY pv.id
) AS pv30
ON pv30.id = p.id
LEFT JOIN (
SELECT id, count(id) cnt_week
FROM `wp_post_views` pv
WHERE pv.time >= CURDATE() - INTERVAL 7 DAY
GROUP BY pv.id
) AS pv7
ON pv7.id = p.id
LEFT JOIN (
SELECT id, count(id) cnt_day
FROM `wp_post_views` pv
WHERE pv.time >= CURDATE() - INTERVAL 1 DAY
GROUP BY pv.id
) AS pv1
ON pv1.id = p.id
ORDER BY pv30.cnt_month DESC, pv7.cnt_week DESC, pv1.cnt_day DESC
LIMIT 10;
itemprop="name"??
UPDATE wp_posts
SET post_content = REGEXP_REPLACE(
post_content,
'<h1[^>]+>[a-zа-я[:space:][:digit:][:punct:]]+</h1>[[:space:]]*',
''
);
CREATE TABLE employees(id INT PRIMARY KEY, name VARCHAR(45), age INT);
INSERT INTO employees(id, name, age) VALUES (1,'John', 34);
INSERT INTO employees(id, name, age) VALUES (2,'Mary', 40);
INSERT INTO employees(id, name, age) VALUES (3,'Mike', 44);
SELECT JSON_PRETTY(JSON_ARRAYAGG(
JSON_OBJECT("id", id, "name", name, "age", age)
)) json
FROM employees
[
{
"id": 1,
"age": 34,
"name": "John"
},
{
"id": 2,
"age": 40,
"name": "Mary"
},
{
"id": 3,
"age": 44,
"name": "Mike"
}
]
select
replace(replace(replace(replace(phones,', ',' '),'"',''),'[',''),']','') phones
from clients;