mirror of
				https://github.com/grocy/grocy.git
				synced 2025-10-31 18:49:38 +00:00 
			
		
		
		
	
		
			
	
	
		
			16 lines
		
	
	
		
			320 B
		
	
	
	
		
			MySQL
		
	
	
	
	
	
		
		
			
		
	
	
			16 lines
		
	
	
		
			320 B
		
	
	
	
		
			MySQL
		
	
	
	
	
	
|   | ALTER TABLE stock
 | ||
|  | ADD location_id INTEGER;
 | ||
|  | 
 | ||
|  | ALTER TABLE stock_log
 | ||
|  | ADD location_id INTEGER;
 | ||
|  | 
 | ||
|  | CREATE VIEW stock_current_locations
 | ||
|  | AS
 | ||
|  | SELECT
 | ||
|  | 	s.product_id,
 | ||
|  | 	IFNULL(s.location_id, p.location_id) AS location_id
 | ||
|  | FROM stock s
 | ||
|  | JOIN products p
 | ||
|  | 	ON s.product_id = p.id
 | ||
|  | GROUP BY s.product_id, IFNULL(s.location_id, p.location_id);
 |