aggregate-functions

MYSQL CONCAT MAX LENGTH

ⅰ亾dé卋堺 提交于 2019-11-28 11:07:16
Following this post: POST ABOUT CONCAT My problem is that i have many rows CONCAT into one row. For example if i have 10 rows with string around 50 chars, my query will show me only 6-7 of that rows or something like that. I searech in stack and google and i found that i can change CONCAT max length by command: SET group_concat_max_len := @@max_allowed_packet . What i am doing wrong? EDIT: When i SHOW VARIABLES LIKE 'group_concat_max_len' it's shows me 1024. Mysql version 5.0.96-log. Tables type: MyISAM. Looks like it dont have any limits, i try to select simple varchar with 2000 chars, and it

NHibernate - QueryOver criteria appearing in Where instead in Having clause, error

℡╲_俬逩灬. 提交于 2019-11-28 10:37:14
问题 I have a problem in QueryOver where using Group by and have some criteria in where clause. Want to move some criteria with SUM() values in Having clause but every time it appears in Where clause and result in error. **Error** ="*An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference*" Conjunction conjunction = Restrictions.Conjunction(); Conjunction havingconjun =

Weekly total sums

送分小仙女□ 提交于 2019-11-28 10:32:31
问题 I have a table in a PostgreSQL database containing dates and a total count per day. mydate total 2012-05-12 12 2012-05-14 8 2012-05-13 4 2012-05-12 12 2012-05-15 2 2012-05-17 1 2012-05-18 1 2012-05-21 1 2012-05-25 1 Now I need to get the weekly totals for a given date range. Ex. I want to get the weekly totals from 2012-05-01 up to 2012-05-31 . I'm looking at this output: 2012-05-01 2012-05-07 0 2012-05-08 2012-05-14 36 2012-05-15 2012-05-22 5 2012-05-23 2012-05-29 1 2012-05-30 2012-05-31 0

Using GROUP BY with FIRST_VALUE and LAST_VALUE

夙愿已清 提交于 2019-11-28 09:54:36
I'm working with some data that is currently stored in 1 minute intervals that looks like this: CREATE TABLE #MinuteData ( [Id] INT , [MinuteBar] DATETIME , [Open] NUMERIC(12, 6) , [High] NUMERIC(12, 6) , [Low] NUMERIC(12, 6) , [Close] NUMERIC(12, 6) ); INSERT INTO #MinuteData ( [Id], [MinuteBar], [Open], [High], [Low], [Close] ) VALUES ( 1, '2015-01-01 17:00:00', 1.557870, 1.557880, 1.557870, 1.557880 ), ( 2, '2015-01-01 17:01:00', 1.557900, 1.557900, 1.557880, 1.557880 ), ( 3, '2015-01-01 17:02:00', 1.557960, 1.558070, 1.557960, 1.558040 ), ( 4, '2015-01-01 17:03:00', 1.558080, 1.558100, 1

dplyr: filter rows according to aggregated function result

人走茶凉 提交于 2019-11-28 09:53:23
问题 I have a table listing (amount, year and month) and I want to filter the rows corresponding to complete years. I.e. I want to ommit the last 4 rows of the sample dataframe I give below, that refer to 2015, and get the rest 60. Is it possible to do that with a single dplyr command? I tried this: df %>% group_by(year) %>% tally() %>% filter (n==12) %>% ungroup() but I guess ungroup does something different than what I want. Is it possible to do that with a single dplyr command? df <- structure

Truncate timestamp to arbitrary intervals

老子叫甜甜 提交于 2019-11-28 09:18:59
问题 I want to plot my_values with some lower resolution on the time axis than I have in the database. I use something like the following SQL to get the average values per time interval (e.g., an hour): SELECT DATE_TRUNC('hour', my_timestamps) AS my_time_lowres , AVG(my_values) FROM my_table GROUP BY my_time_lowres Using date_trunc() it is possible to reduce the resolution of the timestamp to a certain degree (according to the docs): select date_trunc('hour', timestamp '2001-02-16 20:38:40') --

use mysql SUM() in a WHERE clause

五迷三道 提交于 2019-11-28 07:57:55
suppose I have this table id | cash 1 200 2 301 3 101 4 700 and I want to return the first row in which the sum of all the previous cash is greater than a certain value: So for instance, if I want to return the first row in which the sum of all the previous cash is greater than 500, is should return to row 3 How do I do this using mysql statement? using WHERE SUM(cash) > 500 doesn't work You can only use aggregates for comparison in the HAVING clause: GROUP BY ... HAVING SUM(cash) > 500 The HAVING clause requires you to define a GROUP BY clause. To get the first row where the sum of all the

MySQL Querying Aggregate of Non Overlapping Dates

China☆狼群 提交于 2019-11-28 06:49:03
问题 Let's assume that the following data stream is given: CREATE TABLE reservation ( id bigint(20), start_datetime DATETIME NOT NULL, end_datetime DATETIME ); 1. The First Data Stream INSERT INTO reservation (id, start_datetime, end_datetime) VALUES (1, '2015-05-01 00:00:00', '2015-05-03 00:00:00'), (2, '2015-05-02 00:00:00', '2015-05-05 00:00:00'), (3, '2015-05-03 00:00:00', '2015-05-04 00:00:00'), (4, '2015-05-05 00:00:00', '2015-05-07 00:00:00'); For the first insert values id = 1, 2, 3, and 4

MYSQL how to select data where a field has a min value

╄→гoц情女王★ 提交于 2019-11-28 05:49:36
Please I want to select data from a table, where a specific field has the min value, I've tried this : SELECT * FROM pieces where min(price) I'm not good with MySQL, please any help ? Thanks this will give you result that has the minimum price on all records. SELECT * FROM pieces WHERE price = ( SELECT MIN(price) FROM pieces ) SQLFiddle Demo This is how I would do it (assuming I understand the question) SELECT * FROM pieces ORDER BY price ASC LIMIT 1 If you are trying to select multiple rows where each of them may have the same price (which is the minimum) then @JohnWoo's answer should suffice

Aggregate String Concatenation in Oracle 10g [duplicate]

不羁的心 提交于 2019-11-28 05:22:59
问题 This question already has an answer here: Concatenate results from a SQL query in Oracle 7 answers I'm using Oracle 10 g, I have a scenario similar to this: No Name -- ----- 1 Rony 1 James 1 Aby 2 Sam 2 Willy 3 Mike I need to aggregate and concatenate the strings (with a single space in between), in a way to get the results: No Name -- ----- 1 Rony James Aby 2 Sam Willy 3 Mike I'm using Oracle 10g and have to implement this using SQL and not PL/SQL. Is there a way out? 回答1: It is easy on 11G,