mirror of
				https://github.com/grocy/grocy.git
				synced 2025-10-31 18:49:38 +00:00 
			
		
		
		
	
		
			
	
	
		
			13 lines
		
	
	
		
			446 B
		
	
	
	
		
			MySQL
		
	
	
	
	
	
		
		
			
		
	
	
			13 lines
		
	
	
		
			446 B
		
	
	
	
		
			MySQL
		
	
	
	
	
	
|   | CREATE VIEW stock_current_location_content
 | ||
|  | AS
 | ||
|  | SELECT
 | ||
|  | 	IFNULL(s.location_id, p.location_id) AS location_id,
 | ||
|  | 	s.product_id,
 | ||
|  | 	SUM(s.amount) AS amount,
 | ||
|  | 	MIN(s.best_before_date) AS best_before_date,
 | ||
|  | 	IFNULL((SELECT SUM(amount) FROM stock WHERE product_id = s.product_id AND location_id = s.location_id AND open = 1), 0) AS amount_opened
 | ||
|  | FROM stock s
 | ||
|  | JOIN products p
 | ||
|  | 	ON s.product_id = p.id
 | ||
|  | GROUP BY IFNULL(s.location_id, p.location_id), s.product_id;
 |