YehYeh 記事本2.0

Version 0.8.3

竹科碼農的記事本

SQLite - SQL Sample

with 
	sp(stock_id, date, price) AS (
		SELECT stock_id, date, 收盤價
		FROM price
		WHERE stock_id in ('2330', '2610', '2618', '2603', '2731', '5706', '2704', '9943', '3596', '00752', '0056', '2727', '2729', '1268', '2633', '2207', '8044', '8454', '4938', '2884', '4919', '2412', '1303', '1301', '6505', '1326')
			and date = '2020-01-20 00:00:00'	
	), 
	ep(stock_id, date, price) AS (
		SELECT stock_id, date, 收盤價
		FROM price
		WHERE stock_id in ('2330', '2610', '2618', '2603', '2731', '5706', '2704', '9943', '3596', '00752', '0056', '2727', '2729', '1268', '2633', '2207', '8044', '8454', '4938', '2884', '4919', '2412', '1303', '1301', '6505', '1326')
			and date = '2020-04-15 00:00:00'	
	),
	sn(stock_id, stock_name) as (
		SELECT stock_id, stock_name from stock_name
	)
SELECT 	
	sn.stock_id, 
	stock_name, 
	sp.price AS Price0120, 
	ep.price AS Price0420,
	ep.price-sp.price PriceDiff,
	Round((ep.price-sp.price)/sp.price*100,2) || '%' PriceDiffPercent
FROM sp, ep, sn
WHERE sp.stock_id = ep.stock_id
	AND sp.stock_id = sn.stock_id
ORDER BY Round((ep.price-sp.price)/sp.price*100,2) 	
	
SELECT stock_id, date, 收盤價
FROM price
WHERE stock_id in ('2330', '2610', '2618', '2603', '2731', '5706', '2704', '9943', '3596', '00752', '0056', '2727', '2729', '1268', '2633', '2207', '8044', '8454', '4938', '2884', '4919', '2412', '1303', '1301', '6505', '1326')
	and date = '2020-04-14 00:00:00'
order by 1	
Last updated on 2020-04-03
Published on 2020-04-03
Edit on GitHub