aggregate-functions

Howto aggregate on full data set in Spring Batch jobs?

扶醉桌前 提交于 2019-12-11 13:05:24
问题 I need to insert aggregation in my Spring Batch jobs. But the aggregation step need to have the entire data set available. In pure SQL, it's easy to code SQL aggregation requests : the full data set (as stored in database) is available. But in Spring Batch jobs, everything is done in memory, and spread in chunked. So howto deal with that kind of data strewing ? Do you have any advice concerning the best practices to insert aggregation steps/processes ? Thx a lot for your enlightments 回答1: You

Teradata SQL tuning with Sum and other aggregate functions

蹲街弑〆低调 提交于 2019-12-11 12:21:41
问题 I have a query like sel tb1.col1, tb4.col2, (case WHEN t4.col4 in (<IN LIST with more than 1000 values!>) then T4.Col7 Else "Flag" ) as "Dcol1", Sum ( tb3.col1), sum (tb3.col2 ), sum (tb2.col4) etc from tb1 left outer join tb2 <condition> LOJ tb3 <conditions> where tb1 condition and tb2 condition and tb3 condition group by ( case <condition> , colx.tb2,coly.tb1 Problem is TB3 and TB4 are HUGE fact table. The PI of the fact table is NOT included in the joins or Queries here. What I have done

How can I combine multiple rows into one column using PostgreSQL?

最后都变了- 提交于 2019-12-11 11:18:35
问题 How can I combine multiple results into one column? For example, my query displays this result: internaldocid | document id | versionid | title | tagname 1146 | DOC-1146 | 2 | Press Release | tag1 1146 | DOC-1146 | 2 | Press Release | tag2 1146 | DOC-1146 | 2 | Press Release | tag3 I would like it to display this result: internaldocid | document id | versionid | title | tagname 1146 | DOC-1146 | 2 | Press Release | tag1, tag2, tag3 Here is my SQL: SELECT cmsdocument.internaldocid, cmsdocument

SUM & GROUP BY on an array of composite type

为君一笑 提交于 2019-12-11 10:59:25
问题 I have a column with an array of composite type (text, decimal, timestamp) as data type. I want to create a query to sum the total of the double column of the composite type. Also I want to perform a group by on the date(day-month-year) of the date time. Can anyone show me an example of explain how this an be done? Definition of table and type: create type stage as ( Stage_Name text, Stage_Distance decimal, Stage_Start_Time timestamp ); CREATE TABLE "Event" ( "Id" serial NOT NULL, "Location"

Sum of time difference between rows

北城余情 提交于 2019-12-11 10:23:15
问题 I have a table which records every status change of an entity id recordTime Status ID1 2014-03-01 11:33:00 Disconnected ID1 2014-03-01 12:13:00 Connected ID2 2014-03-01 12:21:00 Connected ID1 2014-03-01 12:24:00 Disconnected ID1 2014-03-01 12:29:00 Connected ID2 2014-03-01 12:40:00 Disconnected ID2 2014-03-01 13:03:00 Connected ID2 2014-03-01 13:13:00 Disconnected ID2 2014-03-01 13:29:00 Connected ID1 2014-03-01 13:30:00 Disconnected I need to calculate the total inactive time i.e time

Using a variable in MySQL Select Statment in a Where Clause

心已入冬 提交于 2019-12-11 10:10:12
问题 I would like to know if it's possible to find a value in a select statement and use it in a where clause like: SELECT col1, MAX(col2) - COUNT(DISTINCT col3) as variable FROM table WHERE col1 > variable "table" is pretty big, and I want to narrow down the records the query has to look at as quickly as possible. I know this isn't bit of code isn't possible as written (#1054 - Unknown column 'variable' in 'where clause'), but is there anyway to figure out the value of "variable" and then use it

HQL combining aggregate functions

江枫思渺然 提交于 2019-12-11 09:38:02
问题 My problem is that I cannot use those two aggregate functions together like in the query: AVG(MIN(, First I need to obtain the minimum value from that entity termResultCurrent and after that the average of all the minimum values. Probably it must be changed the group by and include some other clause to fetch just the minimum value (I don't know if that is possible). Otherwise, it might be using subqueries but I had problems with the group by... I know it is quite challenging but I do

T-SQL Combine Multiple Rows Into Single Row

天大地大妈咪最大 提交于 2019-12-11 09:16:11
问题 I have this T-SQL (simplified): select 3.00 as score1, null as score2, null as score3, null as score4 union all select null as score1, 4.5 as score2, 1.5 as score3, null as score4 Which produces this: score1 score2 score3 score4 ------------------------------ 3.00 NULL NULL NULL NULL 4.5 1.5 NULL But i want to join it into one row, like this: score1 score2 score3 score4 ------------------------------ 3.00 4.5 1.5 NULL Sorry - im drawing blank (it's late in the day). Do i need a temporary

Group by and sum

北城余情 提交于 2019-12-11 08:59:46
问题 I am having trouble getting the sum of enrollment where the business_code is the same. My code is the following: SELECT DISTINCT lb.building_code , lb.bus_code, gl.building_name, gl.bus_name, SUM(gl.enrollment) AS enrollment FROM table1 AS gl RIGHT OUTER JOIN table 2 AS lb ON gl.building_key = lb.building_key where gl.bus_name = 'Business' and gl.year_cd = 2010 GROUP BY lb.building_code, lb.bus_code, gl.building_name, gl.bus_name, gl.enrollment Current output: building_code bus_code bus_name

How to perform aggregate function on last 4 rows of data?

别说谁变了你拦得住时间么 提交于 2019-12-11 08:23:42
问题 I've got a table off the following model. public class WeeklyNums { public int FranchiseId { get; set; } public DateTime WeekEnding { get; set; } public decimal Sales { get; set; } } I need a fourth column that calculates the minimum for this week and the previous three weeks. So the output would look like this. 1 7-Jan $1 1 14-Jan $2 1 21-Jan $3 1 28-Jan $4 **1** 1 4-Feb $4 **2** 1 11-Feb $6 **3** 1 18-Feb $4 **4** 1 25-Feb $8 **4** 1 3-Mar $7 **4** I have no idea where to even start. Even