Understanding query options in graph and stat panels

In setting up a graph panel with influxdb, there are two time options. The first is adjacent to the Query Options line (here it is 2s) and varies according to the time span of the graph. The second is the Group By time, here 1s. How are these different?

In a Stat Panel, using the same query, there is a further “time” setting - you can specify a Calculation: Last, Last (not null) … mean. For the Mean - over what range in samples or time is the Mean calculated? it gives quite different results.