select * from (
select DISTINCT (regexp_split_to_array(commend, E'\\s+'))[:3] as words from orders
) t
order by words[2]
select client_id, st, en, avg(bal)
from (
select *,
max(day) filter (where l = 1) over (partition by client_id order by day) st,
min(day) filter (where r = 1) over (partition by client_id order by day range between current row and unbounded following) en
from (
select *,
case when (lag(bal) over w) > 0 then 0 else 1 end as l,
case when (lead(bal) over w) > 0 then 0 else 1 end as r
from balance
window w as (partition by client_id order by day)
) t
where bal > 0
) t1 group by client_id, st, en
order by 1, 2
SELECT * FROM table1 CROSS JOIN table2
, даже если в таблицах есть такие колонки), но чаще нет. В предикате JOIN ON или в WHERE нужно знать, о колонке какой таблицы идет речь. select date_trunc('hour', e.created), avg(e.value) from table e group by 1 order by 1
[00:00-07:00)
[07:00-14:00)
[14:00-21:00)
[21:00-00:00) - следующий день
[00:00-07:00) - следующий день
[00:00-07:00)
[07:00-14:00)
[14:00-21:00)
[21:00-03:00) - следующий день
[03:00-10:00) - следующий день
...
select date_trunc('day', e.created) + (trunc(extract('hour' from e.created) / 7) * 7 || ' hour')::interval, avg(e.value) from table e group by 1 order by 1
INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`) VALUES
( '__plugins_cache_244', 'test1', 'no')
...
INSERT INTO `wp_options` (`option_id`, `option_name`, `option_value`, `autoload`) VALUES
(DEFAULT, '__plugins_cache_244', 'test1', 'no')
...
select
region_code, ...
sum(case when status_id = 2 then 1 else 0 end) - sum(case when consul_need_id = 3 then 1 else 0 end) as diff, ...
select t.*,
"Всего детей",
"Всего детей" - "18.1",
"18.1" * "До года жизни" / ("7.1" + "8.1")
...
from (
select
region_code, sum(case when age_group_id < 13 then 1 else 0 end) as "До года жизни",
....
) t
(sum(case when ... end),0)
- зачем оно вам? Какой смысл тогда в ON DELETE CASCADE?
select `Date`, source, Campaign, Ad, SUM(Click), SUM(Cost), SUM(`App Install`), SUM(Purchase)
from (
select `Date`, 'source A' as source, Campaign, Ad, Click, Cost, null as `App Install`, null as Purchase from table1
union
select date(`DateTime`), 'source B', Campaign, Ad, Click, Cost, null, null from table2
union
select `Date`, Source, Campaign, Ad, null, null, `App Install`, Purchase from table3
) t
group by `Date`, source, Campaign, Ad
SELECT Company, SUM(CASE WHEN IsDiscounted THEN Price ELSE -Price END) ...
sql.execute("""CREATE TABLE IF NOT EXISTS users(
id INT
balance BIGINT
name TEXT)""")
CREATE TABLE IF NOT EXISTS users(
id INT,
balance BIGINT,
name TEXT)
UPDATE `Work`
SET `DateClose` = ( CASE WHEN `DateClose` IS NULL THEN '2021-04-26 21:34:30' END )
WHERE `Work`.id = 6;
Есть ли более хитрый метод, чем просто хранить файлы расширения .sql локально?да нет, скорее всего. Git в любом случае работает с файлами.
=, <, >, <>
- да= | TRUE FALSE NULL
________________________________
TRUE | TRUE FALSE NULL
FALSE | FALSE TRUE NULL
NULL | NULL NULL NULL
SELECT SUCCESS * 100 / (SUCCESS + UNSUCCESS) FROM (
SELECT
COUNT(*)FILTER(WHERE STATUS = 1) SUCCESS,
COUNT(*)FILTER(WHERE STATUS != 1) UNSUCCESS,
FROM TABLE
) AS T