考虑以下两个类和接口:
public class Class1 {}
public class Class2 {}
public interface Interface1 {}
Run Code Online (Sandbox Code Playgroud)
为什么第二次mandatory调用重载方法与Class2, ifgetInterface1和与Interface1无关Class2?
public class Test {
public static void main(String[] args) {
Class1 class1 = getClass1();
Interface1 interface1 = getInterface1();
mandatory(getClass1()); // prints "T is not class2"
mandatory(getInterface1()); // prints "T is class2"
mandatory(class1); // prints "T is not class2"
mandatory(interface1); // prints "T is not class2"
}
public static <T> void mandatory(T o) {
System.out.println("T is …Run Code Online (Sandbox Code Playgroud) 我有一个表格,用于跟踪某些商店和产品的库存随时间的变化。该值是绝对库存,但我们仅在库存发生变化时插入新行。这种设计是为了保持表较小,因为预计它会快速增长。
这是一个示例架构和一些测试数据:
CREATE TABLE stocks (
id serial NOT NULL,
store_id integer NOT NULL,
product_id integer NOT NULL,
date date NOT NULL,
value integer NOT NULL,
CONSTRAINT stocks_pkey PRIMARY KEY (id),
CONSTRAINT stocks_store_id_product_id_date_key
UNIQUE (store_id, product_id, date)
);
insert into stocks(store_id, product_id, date, value) values
(1,10,'2013-01-05', 4),
(1,10,'2013-01-09', 7),
(1,10,'2013-01-11', 5),
(1,11,'2013-01-05', 8),
(2,10,'2013-01-04', 12),
(2,11,'2012-12-04', 23);
Run Code Online (Sandbox Code Playgroud)
我需要能够确定每个产品和商店的开始日期和结束日期之间的平均库存,但我的问题是简单的 avg() 没有考虑到库存在更改之间保持不变。
我想要的是这样的:
select s.store_id, s.product_id , special_avg(s.value)
from stocks s where s.date between '2013-01-01' and '2013-01-15'
group by s.store_id, s.product_id
Run Code Online (Sandbox Code Playgroud)
结果是这样的: …