aggregate-functions

creating multiple custom aggregation functions

对着背影说爱祢 提交于 2019-12-25 09:49:29
问题 I have this table named Account. A simplified view of this table is as follows: acct_num | ssn | branch | open_date |close_date | has_product1 | has_product2 ---------------------------------------------------------------------------------------- 0123456 | 123456789 | 01 | 01/01/2000 | NULL | 1 | 0 0123457 | 123456789 | 02 | 03/05/2004 | NULL | 0 | 1 1234405 | 322145678 | 04 | 04/16/2016 | 05/01/2016 | 1 | 1 ... Notice how the ssn 123456789 has 2 accounts. I need to create a new data set that

Use of 'median' function in calculated field in SSRS

若如初见. 提交于 2019-12-25 08:49:55
问题 According to this it looks like you can use an aggregate function in a calculated field, but if I try and use the median command, I get an error "the value expression for the field =Median( ...what I wrote below..) contains an error: BC30451 Name 'Median' is not declared. I have tried =Median(Fields!name_of_field_I_want_median_from.Value,"dsTheDatasetFieldIsIn") and =Median(Fields!name_of_field_I_want_median_from.Value) neither work N.B. Dataset is derived from MDX 回答1: maybe I didn't

MS Access - SQL Query for Average of Each Day Data

巧了我就是萌 提交于 2019-12-25 08:33:38
问题 I have a set of data spanning across 3 days. Based on the first column from the left, is it possible to have a query that calculates the average of the values in the third column from the left based on each day? The end result will be two columns: 1/1/2008 | 1.605 2/1/2008 | 1.59 3/1/2008 | 1.56 I think the logic will be something like in a loop: Based on the day in the first column, if it is the same day, count the number of rows and add up the values of the third column Use the sum of the

Get column values from multiple rows as array

冷暖自知 提交于 2019-12-25 07:48:26
问题 I am trying to fetch column values as an array in order to use them in the function array_agg_transfn() to calculate the median value as defined in the Postgres Wiki. The column values of a particular column I fetch based on the current row. For example, 13 rows below the current row. I tried using the following query: select a."Week_value", array_agg(a."Week_value") over(order by prod_name,week_date desc rows between 0 preceding and 12 following) from vin_temp_table But got this error

How to get count from mapping table group be another table in PostgreSQL?

雨燕双飞 提交于 2019-12-25 07:27:09
问题 I have three tables: store ===== name address city state country tag ..., post ======= title summary tags ... store_post_map ================ (mapping on store and post based on tag). Now I want to get count of posts from mapping table group by city , state , country or store.id , what to be the SQL in PostgreSQL? 回答1: Basically, it's this: SELECT store_id, count(*) AS posts_ct FROM store_post_map GROUP BY store_id; How can we get counts for each city, state or country where each area can

Trying to get the sum of distinct values for distinct files for distinct software versions

萝らか妹 提交于 2019-12-25 06:46:55
问题 I'm working in SQL Server Management Studio. I've got a table that has simulation data in it. Four of the columns are "Version", "Scenario_Name", "Measure", and "Value". The "Version" column will have the software version number in it. The "Scenario_Name" column will have the file names for the scenario in them. The "Measure" column will have essentially a data type entry for the scenario something like Time, Money, Costs, etc. The "Value" column will record the number that is associated with

MYSQL COUNT return NULL?

爷,独闯天下 提交于 2019-12-25 05:29:07
问题 I have googled my problem but didnt get the answer. I want to list all of the results of below sql including NULL (when COUNT(review.id) return 0 also) but instead i just got the results of articles of place that only contains review. $sql = "SELECT tbl_place.id, tbl_place.region_id, tbl_place.subregion_id, tbl_place.title, tbl_place.metalink, tbl_place.img_thumbnail, tbl_place.summary, tbl_place.category1_id, tbl_place.category2_id, tbl_place.category3_id, COUNT(review.id) AS total_review

Adding First Values Grouped by ID from record set; report builder 3.0

故事扮演 提交于 2019-12-25 04:00:33
问题 I have a dataset being returned that has monthly values for different 'Goals.' The goals has unique ID's and the month/date values will always be the same for the goals. The difference is sometimes one goal doesn't have values for all the same months as the other goal because it might start at a later date, and i want to 'consolidate' the results and sum them together based on the 'First' startBalance for each goal. Example dataset would be; goalID monthDate startBalance 1 1/1/2014 10 1 2/1

Access & SQL Server: Number of uses since date aggregate problem - new reporting problem (solved aggregate issue)

蹲街弑〆低调 提交于 2019-12-25 03:48:06
问题 BACKGROUND: I've been trying to streamline the work involved in running a report in my program. Lately, I've had to supply a listing of job numbers an instrument has been used on with the listing of items for cost/benefit analysis. Mostly to see how often an instrument is used since it was last serviced/calibrated and the last time anyone did use it. I was looking to integrate this into the query that helps generate the report - but I keep hitting a brick wall of sorts with the number of uses

Summing and ordering at once

做~自己de王妃 提交于 2019-12-25 02:55:51
问题 I have a table of orders. There I need to find out which 3 partner_id's have made the largest sum of amount_totals, and sort those 3 from biggest to smallest. testdb=# SELECT amount_total, partner_id FROM sale_order; amount_total | partner_id --------------+------------ 1244.00 | 9 3065.90 | 12 3600.00 | 3 2263.00 | 25 3000.00 | 10 3263.00 | 3 123.00 | 25 5400.00 | 12 (8 rows) Just starting SQL, I find it confusing ... 回答1: Aggregated amounts If you want to list aggregated amounts, it can be