aggregate-functions

Selecting an average of records grouped by 5 minute periods

纵饮孤独 提交于 2019-12-01 11:21:13
问题 I'm having a slight issue. I have a PostgreSQL table with such format time (datetime) | players (int) | servers (int) --------------------------------------------------- 2013-12-06 13:40:01 | 80 | 20 2013-12-06 13:41:13 | 78 | 21 etc. I would like to group them by 5 minute periods and get an average of the group as a single value, so there will be 20% of the records, each containing an average of ~5 numbers, with time set to the first time value in the group. I have no idea how to do this in

Build dynamic query(dynamic operator) in SSRS using a complex query

試著忘記壹切 提交于 2019-12-01 09:16:12
I would like to build a dynamic query for a specific report using some parameters (dynamic operators). How can I add dynamic parameters without writing/editing the expression? Because my query is complex, included three-join tables and aggregations I think this might be cause the error. Can I join tables within an expression in dataset properties? SELECT a.CaseNo, a.PatientName, a.PolicyNumber, FROM Cases a INNER JOIN GOPs b ON a.CaseNo = b.CaseNo INNER JOIN Invoices d ON d.CaseNo = a.CaseNo WHERE (a.CreatedDate >= @StartDate AND a.CreatedDate <= @EndDate +1) This query is working properly if

SQLite count example

本秂侑毒 提交于 2019-12-01 08:53:15
I am using SQLite in Android. I have the query, query executed and how to print count from cursor. Cursor dataCount = mDb.rawQuery("select count(*) from " + DATABASE_JOURNAL_TABLE, null); I have no record in table. Harry Joy May be by getInt(index) as cursor.getInt(1); // this is for example, you have to adjust index in your code Also cursor has a built in function getCount() to return row number so can also do like this: // assuming your table has `id` column as primary key or unique key. Cursor dataCount = mDb.rawQuery("select id from " + DATABASE_JOURNAL_TABLE, null); dataCount.getCount();

MySQL Select Query to generate dynamic column Result

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 08:51:28
I need to write a query that returns a Column Dynamically. For example I have a table tblTest with columns: Id, Name, Type, Amount 1, Receipt, Cash 100 2, Receipt, Card 200 3, Receipt, Cheque 250 4, Receipt, Card 150 5, Receipt, Cash 100 6, Payment, Cash 300 7, Payment, Cheque 400 SQL Query : SELECT Name, SUM(CASE WHEN Type = 'Cash' THEN Amount ELSE 0 END) Cash, SUM(CASE WHEN Type = 'Card' THEN Amount ELSE 0 END) Card, SUM(CASE WHEN Type = 'Cheque' THEN Amount ELSE 0 END) Cheque FROM tblTest GROUP BY Name; it returns me, above result is as per my requirement but in my case Type Cash,Card

Aggregate functions on multiple joined tables

梦想的初衷 提交于 2019-12-01 08:26:32
问题 I have three tables: CREATE TABLE foo ( id bigint PRIMARY KEY, name text NOT NULL ); CREATE TABLE foo_bar ( id bigint PRIMARY KEY, foo_id bigint NOT NULL ); CREATE TABLE tag ( name text NOT NULL, target_id bigint NOT NULL, PRIMARY KEY (name, target_id) ); I'm trying to create a view such that I get all of the fields of table foo , the count of items in foo_bar where foo.id = foo_bar.foo_id , and a text array of all tags where foo.id = tag.target_id . If we have: INSERT INTO foo VALUES (1,

MySQL MIN/MAX returning proper value, but not the related record info

落爺英雄遲暮 提交于 2019-12-01 06:58:53
问题 I am really stuck on this. I'm clearly not understanding the MIN/MAX concept. I am trying to get the latest row from a grouping of work_type and work_id. If I change from MIN to MAX, it changes the returned timestamp, but it never brings the status info from that record. Example: "SELECT CONCAT(work_type, work_id) AS condition_id, status, MIN(created_timestamp) as latest FROM conditions GROUP BY condition_id" With MIN, I get: Array ( [0] => Array ( [condition_id] => cutouts00002 [status] =>

SQLite count example

雨燕双飞 提交于 2019-12-01 06:40:59
问题 I am using SQLite in Android. I have the query, query executed and how to print count from cursor. Cursor dataCount = mDb.rawQuery("select count(*) from " + DATABASE_JOURNAL_TABLE, null); I have no record in table. 回答1: May be by getInt(index) as cursor.getInt(1); // this is for example, you have to adjust index in your code Also cursor has a built in function getCount() to return row number so can also do like this: // assuming your table has `id` column as primary key or unique key. Cursor

Build dynamic query(dynamic operator) in SSRS using a complex query

我是研究僧i 提交于 2019-12-01 06:30:22
问题 I would like to build a dynamic query for a specific report using some parameters (dynamic operators). How can I add dynamic parameters without writing/editing the expression? Because my query is complex, included three-join tables and aggregations I think this might be cause the error. Can I join tables within an expression in dataset properties? SELECT a.CaseNo, a.PatientName, a.PolicyNumber, FROM Cases a INNER JOIN GOPs b ON a.CaseNo = b.CaseNo INNER JOIN Invoices d ON d.CaseNo = a.CaseNo

MySQL Select Query to generate dynamic column Result

时光怂恿深爱的人放手 提交于 2019-12-01 06:08:16
问题 I need to write a query that returns a Column Dynamically. For example I have a table tblTest with columns: Id, Name, Type, Amount 1, Receipt, Cash 100 2, Receipt, Card 200 3, Receipt, Cheque 250 4, Receipt, Card 150 5, Receipt, Cash 100 6, Payment, Cash 300 7, Payment, Cheque 400 SQL Query : SELECT Name, SUM(CASE WHEN Type = 'Cash' THEN Amount ELSE 0 END) Cash, SUM(CASE WHEN Type = 'Card' THEN Amount ELSE 0 END) Card, SUM(CASE WHEN Type = 'Cheque' THEN Amount ELSE 0 END) Cheque FROM tblTest

How to translate the PostgreSQL array_agg function to SQLite?

孤街浪徒 提交于 2019-12-01 04:19:14
This query works in PostgreSQL: Select ot.MCode,array_to_string(array_agg(tk1.TName || ',' || ot.TTime), ' - ') as oujyu_name_list From TR_A ot inner join MS_B tk1 on ot.Code = tk1.Code Where ot.Code in (Select Code From TR_C ) Group byot.MCode but it does not work in SQLite, because SQLite does not have the array_agg() function. How can this query be converted to SQLite? For this query, you can use group_concat , which directly returns a string: SELECT ..., group_concat(tk1.TName || ',' || ot.TTime, ' - ') FROM ... 来源: https://stackoverflow.com/questions/26922230/how-to-translate-the