aggregate-functions

TSQL: Cannot perform an aggregate function AVG on COUNT(*) to find busiest hours of day

安稳与你 提交于 2020-01-02 05:26:08
问题 Consider a SQL Server table that holds log data. The important parts are: CREATE TABLE [dbo].[CustomerLog]( [ID] [int] IDENTITY(1,1) NOT NULL, [CustID] [int] NOT NULL, [VisitDate] [datetime] NOT NULL, CONSTRAINT [PK_CustomerLog] PRIMARY KEY CLUSTERED ([ID] ASC)) ON [PRIMARY] The query here is around finding the distribution of visits BY HOUR of the day. We're interested in seeing the distribution of the average number of visits for the hour in a given date range. The query results would be

Aggregating mean “%H%M” in “week” bins in R

梦想与她 提交于 2020-01-02 04:55:08
问题 I have been struggling with this for a while. I am new to working with ts data and all related R packages. I have a df with several variables including what 'time of day'in GMT "%H%M" and date "%Y/%m/%e" sampling occurred. I want to bin/aggregate my date data into "weeks" (i.e., %W/%g) and calculate the mean 'time of the day' when sampling occurred during that week. I was able to calculate other FUN on numerical variables (e.g., weight) by first transforming my df into a zoo object and then

Aggregate strings in descending order in a PostgreSQL query

懵懂的女人 提交于 2020-01-02 00:59:13
问题 In addition to the question How to concatenate strings of a string field in a PostgreSQL 'group by' query? How can I sort employee in descending order? I am using PostgreSQL 8.4 which doesn't support string_agg() . I've tried to use the following, but it isn't supported: array_to_string(array_agg(employee ORDER BY employee DESC), ',') I'd appreciate any hint to the right answer. 回答1: In PostgreSQL 9.0 or later you can order elements inside aggregate functions: SELECT company_id, array_agg

Running totals in a SQL view

百般思念 提交于 2020-01-01 18:17:27
问题 I am trying to get running totals in my View in SQL Server 2008 Here is my tables BankAccounts ------------ AccountID (KEY) Name Created Transactions ------------ TransactionID (KEY) Description Credit Debit TransDate Created AccountID Here is my query so far.. SELECT t.Created, t.Description, t.Credit, t.Debit, t.TransDate, t.TransactionID, ba.AccountID, (isnull(t.Credit,0)-isnull(t.Debit,0))+COALESCE((SELECT SUM(isnull(Credit,0)) - SUM(isnull(Debit,0)) FROM Transactions b WHERE b.TransDate

Oracle built-in functions metadata

烈酒焚心 提交于 2020-01-01 17:20:35
问题 Is there a way to get metadata for the Oracle built-in aggeregate and other functions such as AVG, STDDEV, SQRT, etc.? I need to know object id and arguments meta. In the SYS.ALL_OBJECTS view I couldn't find anything useful. I also tried to search in SYS.ALL_ARGUMENTS view by object_name. Is there views or tables with built-in functions with data similar to SYS.ALL_OBJECTS and SYS.ALL_ARGUMENTS ? 回答1: You have tagged Oracle 10g, but from what I can find, you'll need Oracle 11g r1 to find out

Oracle built-in functions metadata

邮差的信 提交于 2020-01-01 17:20:12
问题 Is there a way to get metadata for the Oracle built-in aggeregate and other functions such as AVG, STDDEV, SQRT, etc.? I need to know object id and arguments meta. In the SYS.ALL_OBJECTS view I couldn't find anything useful. I also tried to search in SYS.ALL_ARGUMENTS view by object_name. Is there views or tables with built-in functions with data similar to SYS.ALL_OBJECTS and SYS.ALL_ARGUMENTS ? 回答1: You have tagged Oracle 10g, but from what I can find, you'll need Oracle 11g r1 to find out

MySQL aggregate function problem

心已入冬 提交于 2020-01-01 09:02:33
问题 In the following example, why does the min() query return results, but the max() query does not? mysql> create table t(id int, a int); Query OK, 0 rows affected (0.10 sec) mysql> insert into t(id, a) values(1, 1); Query OK, 1 row affected (0.03 sec) mysql> insert into t(id, a) values(1, 2); Query OK, 1 row affected (0.02 sec) mysql> select * from t -> ; +------+------+ | id | a | +------+------+ | 1 | 1 | | 1 | 2 | +------+------+ 2 rows in set (0.00 sec) mysql> select * from t where a < 4; +

MySQL aggregate function problem

六眼飞鱼酱① 提交于 2020-01-01 09:02:28
问题 In the following example, why does the min() query return results, but the max() query does not? mysql> create table t(id int, a int); Query OK, 0 rows affected (0.10 sec) mysql> insert into t(id, a) values(1, 1); Query OK, 1 row affected (0.03 sec) mysql> insert into t(id, a) values(1, 2); Query OK, 1 row affected (0.02 sec) mysql> select * from t -> ; +------+------+ | id | a | +------+------+ | 1 | 1 | | 1 | 2 | +------+------+ 2 rows in set (0.00 sec) mysql> select * from t where a < 4; +

Aggregate functions over arrays

江枫思渺然 提交于 2020-01-01 04:13:07
问题 I have a table like this: +-----+----------------+ | ID | array300 | +-----+----------------+ | 100 | {110,25,53,..} | | 101 | {56,75,59,...} | | 102 | {65,93,82,...} | | 103 | {75,70,80,...} | +-----+----------------+ array300 column is an array of 300 elements. I need to have arrays of 100 elements with every element representing the average of 3 elements of array300 . For this example the answer will be like: array100 {62.66,...} {63.33,...} {80,...} {78.33,...} 回答1: Try something like

SQL frequency distribution query to count ranges with group-by and include 0 counts

走远了吗. 提交于 2019-12-31 14:33:42
问题 Given: table 'thing': age --- 3.4 3.4 10.1 40 45 49 I want to count the number of things for each 10-year range, e.g., age_range | count ----------+------- 0 | 2 10| 1 20| 0 30| 0 40| 3 This query comes close: SELECT FLOOR(age / 10) as age_range, COUNT(*) FROM thing GROUP BY FLOOR(age / 10) ORDER BY FLOOR(age / 10); Output: age_range | count -----------+------- 0 | 1 1 | 2 4 | 3 However, it doesn't show me the ranges which have 0 counts. How can I modify the query so that it also shows the