select *
from (
select id_field, n_field, v_field, dt_field,
(case when dt_field > now()-INTERVAL '2 hours' and
v_field > (LAG(v_field,1,v_field) OVER (partition by n_field order by dt_field)) * X then 1 else 0 end) as pr,
v_field/(case when (LAG(v_field,1,v_field) OVER (partition by n_field order by dt_field)) = 0 then 1
else LAG(v_field,1,v_field) OVER (partition by n_field order by dt_field)
end) as coef
from table ) a
where a.pr = 1
select a.first_letter_fam, a.avg_plateg_by_letter
from (
select substr(n.c_last_name,1,1) as first_letter_fam,
avg(подставить_сюда_полe_месячного платежа)
over (partition by substr(n.c_last_name,1,1)) as avg_plateg_by_letter,
(n_info_cold + n_info_hot) as potr_vody,
avg(n_info_cold + n_info_hot) over () as avg_potr_vody_all
from computation as c, client as n
where c.n_client = n.n_client) as a
where a.potr_vody < a.avg_potr_vody_all
Используйте SQL Server Management Studio (SSMS) для создания запросов к базам данных и хранилищам данных, их проектирования и управления ими, где бы они ни находились: на локальном компьютере или в облаке.
select a.data, b.another_data
from block as a join block_one as b on (a.main_block_id=b.main_block_id)
where a.type = 'one'
union all
select a.data, b.third_data
from block as a join block_two as b on (a.main_block_id=b.main_block_id)
where a.type = 'two'
select distinct a.data,
(case when a.type='one' then b.another_data else c.third_data end) as some_data
from block as a left join block_one as b on (a.type = 'one' and a.main_block_id=b.main_block_id)
left join block_two as c on (a.type = 'two' and a.main_block_id=c.main_block_id)
TRANSFORM Min(last.absent) AS [Min-absent]
SELECT last.studentid, SUM(IIF(last.absent="-1", 1, 0)) AS Total_Absents, SUM(IIF(last.absent="L", 1, 0)) AS Total_Lates
FROM [last]
GROUP BY last.studentid
PIVOT last.am_day;