aggregate-functions

Concatenate rows in select query (in Advantage Data Architect)

不想你离开。 提交于 2020-01-06 19:39:45
问题 How can I concatenate rows in select query? (in Advantage Data Architect) I tried run the following scripts: The first script: declare @str string; set @str = ''; select @str = @str + field_1 from my_table1 But I get a result where all rows contain "false", like this picture: Second script: declare @str string; select @str = coalesce(@str + ', ','') + field_1 from my_table1 This time, all rows are empty (note: the field from "my_table1" is not null). Picture: I tried to search the solution on

Concatenate rows in select query (in Advantage Data Architect)

我怕爱的太早我们不能终老 提交于 2020-01-06 19:39:29
问题 How can I concatenate rows in select query? (in Advantage Data Architect) I tried run the following scripts: The first script: declare @str string; set @str = ''; select @str = @str + field_1 from my_table1 But I get a result where all rows contain "false", like this picture: Second script: declare @str string; select @str = coalesce(@str + ', ','') + field_1 from my_table1 This time, all rows are empty (note: the field from "my_table1" is not null). Picture: I tried to search the solution on

How to average/sum data in a day in SQL Server 2005

无人久伴 提交于 2020-01-06 12:43:29
问题 I'm trying to average data in SQL Server 2005 in a day. Here is what my database look like this if I use simple query as SELECT timestamp, FEED FROM ROASTER_FEED ORDER timestamp Data: timestamp Feed 02/07/2011 12:00:01 1246 02/07/2011 12:00:01 1234 02/07/2011 12:00:01 1387 02/07/2011 12:00:02 1425 02/07/2011 12:00:03 1263 ... 02/07/2011 11:00:01 1153 02/07/2011 11:00:01 1348 02/07/2011 11:00:01 1387 02/07/2011 11:00:02 1425 02/07/2011 11:00:03 1223 .... 03/07/2011 12:00:01 1226 03/07/2011 12

An SQL function for radix conversion algorithm

不想你离开。 提交于 2020-01-06 12:41:08
问题 Do we have anything predefined function in sql server to work with radix conversion? The scenario is function takes a number as an input parameter and returns the binary radix conversion for the given number. For example, if the input is 12, it has to return "2^3+2^2": "5=2^2+2^0" ...And so until 15. The maximum input is 15. So maximum values we need to search for is: 2^0,2^1,2^2,2^3. We can store these 2 to the power values(2^0,2^1,2^2,2^3) in variables and return those variables. For

Aggregation function to get the difference or ratio of two rows in order

和自甴很熟 提交于 2020-01-06 03:40:08
问题 I have a table full of prices, items, and dates. An example of this is: AA, 1/2/3024, 1.22 AA, 1/3/3024, 1.23 BB, 1/2/3024, 4.22 BB, 1/3/3024, 4.23 Within the data there are only two rows per price, and they are ordered by date. How would I condense this data set into a single product row showing the difference from the last price to the previous? [Also this applies to a ratio, so AA would produce 1.23/1.22]. The result should look like AA, todays price-yesterdays price Despite being a sum

How to get number of invoices for last 12 weeks in Postgres

一曲冷凌霜 提交于 2020-01-06 01:35:24
问题 Invoice database contains invoice dates: create table dok ( dokumnr serial primary key, invoicedate date not null ); Dashboard requires comma separated list containing number of invoices for last 12 weeks, e.q 4,8,0,6,7,6,0,6,0,4,5,6 List contains always 12 elements. If there are no invoices for some 7 day interval, 0 should appear. Every element should contain number of invoices for 7 days. Query should find maximum date before current date: select max(invoicedate) as last_date from dok; And

Calculating acceptance_ratio with LEFT JOIN and SELF JOIN and aggregate function

老子叫甜甜 提交于 2020-01-05 07:56:14
问题 Trying to calculate daily acceptance ratios from the 'connecting' table which has 4 fields with sample values: date action sender_id recipient_id '2017-01-05', 'request_link', 'frank', 'joe' '2017-01-06', 'request_link', 'sally', 'ann' '2017-01-07', 'request_link', 'bill', 'ted' '2017-01-07', 'accept_link', 'joe', 'frank' '2017-01-06', 'accept_link', 'ann', 'sally' '2017-01-06', 'accept_link', 'ted', 'bill' Because there are 0 accepts and 1 request on 01-05, its daily acceptance ratio should

SSRS Aggreation on Calculated Field

放肆的年华 提交于 2020-01-04 21:30:39
问题 I am trying to perform an aggregation on a calculated Field in SSRS and am getting the following error: [rsAggregateReportItemInBody] The Value expression for the textrun 'Textbox43.Paragraphs[0].TextRuns[0]' uses an aggregate function on a report item. Aggregate functions can be used only on report items contained in page headers and footers This is the formula I tried to use: =Sum(ReportItems!PlanPurchPrice.Value, "Select_UCPUtilization") In this Case PlanPurcPrice is also an Expression:

SSRS Aggreation on Calculated Field

橙三吉。 提交于 2020-01-04 21:30:06
问题 I am trying to perform an aggregation on a calculated Field in SSRS and am getting the following error: [rsAggregateReportItemInBody] The Value expression for the textrun 'Textbox43.Paragraphs[0].TextRuns[0]' uses an aggregate function on a report item. Aggregate functions can be used only on report items contained in page headers and footers This is the formula I tried to use: =Sum(ReportItems!PlanPurchPrice.Value, "Select_UCPUtilization") In this Case PlanPurcPrice is also an Expression:

How to sum data of two different columns of two different tables?

元气小坏坏 提交于 2020-01-04 09:18:08
问题 i have two tables i my database in which i have two columns in each table one is for userid & one is for showing some numeric data. I just want to add the value of the numeric column but the issue is that it's not compulsory that both the table have same used id. I will try to explain it using example: table1 userid score1 1 200 2 300 table2 userid score2 1 400 so now what i want to do is to sum the score form these two tables as per the user id and show it in a new table like this: userid