aggregate-functions

Oracle SQL Hierarchical Query: Flatten Hierarchy and Perform Aggregation

為{幸葍}努か 提交于 2019-12-08 05:26:21
问题 I am trying to improve performance for a proof of concept I have already written and am having no luck. I think the approach is probably flawed, but I’m struggling to find another solution. I’ve covered all the Ask Tom articles and forum posts I can find. We’re running Oracle 10g R2. We have items arranged in a hierarchical structure. Quantities are defined on the relationships. There are two types of objects in the hierarchy: assemblies that are logical groupings, and items that represent an

Eloquent finding the row with the max value with grouping

主宰稳场 提交于 2019-12-08 05:22:44
问题 Hi I have the problem and solution here http://dev.mysql.com/doc/refman/5.6/en/example-maximum-column-group-row.html which is to find the row with the max of a certain column, grouped by some other value. My question is how do I convert the query below to Eloquent format? SELECT s1.article, dealer, s1.price FROM shop s1 JOIN ( SELECT article, MAX(price) AS price FROM shop GROUP BY article) AS s2 ON s1.article = s2.article AND s1.price = s2.price; Thanks. 回答1: using raw Builder you can use

SQLite - Help optimizing aggregate total of previous rows with multiple conditions

纵然是瞬间 提交于 2019-12-08 02:43:41
问题 I'm trying to get conditional SUMs of the Value column for each record in the table for all of the "previous" records grouped by the same "Category" field value, and the same "Approved" field value, then divided into Negative and Positive sums. In my program, users can create document record in any order, so "previous" is defined as: If Approved =TRUE, then "previous" records have an older ApprovedDate field value than the current record. If the ApprovedDate field values are the same, then

Group by Max

社会主义新天地 提交于 2019-12-08 02:07:39
问题 SELECT tblIssue.SYMB, tblIssue.[PRCE], tblIssue.[Shareholder] FROM tblIssue I am trying to pull the symb and price for the maximum number of shareholder per symb. For example, I would have only 1 line for ASN where the price would be $60.62. SYMB Price Shareholder ASN $0.00 0 ASN $0.00 51 ASN $25.18 0 ASN $25.26 0 ASN $36.00 0 ASN $60.62 231 ASNL $0.00 101 ASR $0.00 4 ASR $0.00 24 ASR $37.17 13 回答1: SELECT i1.* FROM tblIssue i1 LEFT OUTER JOIN tblIssue i2 ON (i1.[SYMB] = i2.[SYMB] AND i1.

Left Join Lateral and array aggregates

夙愿已清 提交于 2019-12-08 01:48:48
问题 I'm using Postgres 9.3. I have two tables T1 and T2 and a n:m relation T1_T2_rel between them. Now I'd like to create a view that in addition to the columns of T1 provides a column that, for each record in T1, contains an array with the primary key ids of all related records of T2. If there are no related entries in T2, corresponding fields of this column shall contain null-values. An abstracted version of my schema would look like this: CREATE TABLE T1 ( t1_id serial primary key, t1_data int

Pyspark Spark DataFrame - Aggregate and filter columns in map type column

泪湿孤枕 提交于 2019-12-08 00:20:01
问题 My DataFrame looks like: | c1 | c2| c3 | |----+---+------- | A | b | 22:00| | A | b | 23:00| | A | b | 09:00| | A | c | 22:00| | B | c | 09:30| I would like to perform some aggregations and create a second DataFrame with 3 columns: c1 : is the column that I want to group by. map_category_room_date : map type, key the c2 and value the lower/min value in c3 . cnt_orig : is the count on how many rows the original group had. Result | c1 | map_category_room_date | cnt_orig | |----------+----------

Mysql: Group by Hour, 0 if no data

旧城冷巷雨未停 提交于 2019-12-07 23:35:10
问题 I have the following query: SELECT count(*) as 'totalCalls', HOUR(`end`) as 'Hour' FROM callsDataTable WHERE company IN ( SELECT number FROM products WHERE products.id IN (@_PRODUCTS)) AND YEAR(`end`) = @_YEAR AND MONTH(`end`) = @_MONTH group by HOUR(`end`) Above query returns only the hours in which there where calls made: totalCalls Hour 2 0 1 2 4 7 98 8 325 9 629 10 824 13 665 15 678 16 665 17 606 18 89 22 5 23 The desired output should be all the hours, and where there are no calls it

MySQL ORDER BY AVG() DESC not working when certain columns are included

人走茶凉 提交于 2019-12-07 21:15:19
问题 I'm doing a query to return all the rows in table1, along with their average rating from table2: SELECT `table1`.`description`, AVG( `table2`.`rating` ) AS avg_rating FROM `table1` LEFT JOIN `table2` ON ( `table2`.`botid` = `table1`.`id` ) GROUP BY `table1`.`id` ORDER BY avg_rating DESC The problem is that even though I specify DESC , the results are being returned ASC : +-------------+------------+ | description | avg_rating | +-------------+------------+ | test2 | 1.0000 | | test3 | 3.0000

Aggregate functions in ADO.NET with GROUP BY functionality

江枫思渺然 提交于 2019-12-07 20:16:36
问题 This is a more direct question stemming from an earlier more general question i had earlier now that I've spend more time looking into ADO.NET I want to take an ADO.NET DataTable and perform the equivalent of a SQL SELECT query with aggregate functions (such as SUM) on some columns, and GROUP BY set for the remaining columns. I then want to take the result and display it in a DataGrid. I understand that I can create a DataView of a DataTable that contains filter criteria and aggregate

Is there any good way to build a comma-separated list in SQL Server?

放肆的年华 提交于 2019-12-07 18:50:04
问题 In Firebird, there's an aggregate called List() that turns multiple results into a comma-separated string. This function does not appear to exist in SQL Server. Is there any equivalent to it that doesn't involve a big, long, ugly, slow workaround using for xml or building your own as a CLR UDF? (Yes, I know about those methods. Looking for something I might not be aware of.) 回答1: No, those are the workarounds you will have to use. We have been asking for a GROUP_CONCAT equivalent since 2006: