SELECT sensor_alerts.*, sensor_instances.location
FROM sensor_instances
LEFT JOIN sensor_alerts ON sensor_instances.id = sensor_alerts.sensorid
первые 20 строкLIMIT and OFFSET или FETCH.
SELECT MONTH(purchase_date) AS mont, SUM(price) AS goods_sum
FROM goods
GROUP BY MONTH(purchase_date)
SELECT YEAR(purchase_date) AS goods_year,
MONTH(purchase_date) AS goods_month,
SUM(price) AS goods_sum
FROM goods
GROUP BY YEAR(purchase_date), MONTH(purchase_date)
ORDER BY 1, 2
SELECT * FROM (
SELECT contr, [time], SUM(val) OVER ( ORDER BY [time] ) AS sumcash
FROM something ) AS cash
WHERE sumcash <= max_cash
category
нет subcategory
для id_subcat (110, 111)
.goods
обрезан id_cat
или нет разделения на подкатегории.SELECT goods.name_goods, subcategory.name_subcat, category.name_cat
FROM goods
LEFT OUTER JOIN category ON goods.id_cat = category.id
LEFT OUTER JOIN subcategory ON goods.id_cat = subcategory.id_subcat / 10
SELECT buy.nomenclature_id,
SUM ( buy.summa )
- (SELECT ISNULL(SUM( sale.summa ),0)
FROM sale WHERE sale. nomenclature_id = buy. nomenclature_id)
FROM buy
GROUP BY buy.nomenclature_id
UNION
SELECT nomenclature_id, - SUM(summa)
FROM sale
GROUP BY nomenclature_id
HAVING (NOT (nomenclature_id IN (SELECT DISTINCT nomenclature_id FROM buy)))
INSERT INTO galaxy (name, type, diametr FLOAT, mass, discovery_date, birth_date FLOAT,
astronomical_object )
VALUES (..., (SELECT MAX('id') FROM astronomical_object))