New answers tagged

0

With correlated subqueries, it would look like this: SELECT Symbol, MIN(DateTime) AS MinDT, MIN(Price) AS MinPrice, MAX(Price) AS MaxPrice, AVG(Price) AS AvgPrice, (SELECT Price FROM stocks AS s2 WHERE s2.Symbol = stock.Symbol AND s2.DateTime = MIN(stocks.DateTime) ) AS OpeningPrice, ...


2

You first query is OK although not entirely correct. You need to be careful with GROUP BY and not have any column in the SELECT list that is not also in the GROUP BY list. So, add the symbol in the group by list. Next, the LIMIT needs an ORDER BY so you are 100% certain that you get always the same results. SQLite (and many other DBMS) may return the same ...


1

In SQL, triggers can be fired "per row" or "per statement". SQLite only supports "per row" triggers (hence why your trigger fires once for each row in your INSERT statement), while SQL Server only supports "per statement" triggers (hence why your statement causes a single firing). Other engines (e.g. DB2 and PostgreSQL) support both sorts of trigger which ...



Top 50 recent answers are included