FAQ Database Discussion Community


Oracle Get sum of distinct group without subquery

sql,oracle,sum,group,partition
I already have a working example which does exactly what I need. Now the problem is, that I'm not really a fan of subqueries and I think there could be a better solution to this problem. So here is my (already) working example: with t as ( select 'Group1' as...

How do i write this SQL query for an ALL condition?

mysql,sql,database,group,having
I need to build an SQL query in MySQL to solve a problem as part of an assignment for class. I've been working at this problem for awhile, but I'm having a hard time figuring out how to structure this query properly. I'm rather new to the SQL language and...

LinkedIn Group API changes

api,rest,group,linkedin
As far as I can tell, with the new changes to the API's, LinkedIn's Group api's are no longer public at all. Are there any ways to access the posts made in a group without using the Group api? All I'm looking to do is to read the posts from...

Regex: Search for a match within a match

regex,match,group
I've seen several "Match within a match" questions but none of the answers fit what I'm trying to do. Right now I have this string: <td title="Click to view the details" class="alignLeft genericName padding2" style="cursor: pointer;">ACETYLCYSTEINE 200MG/ ML INJ <br>COLORLESS (IJ)</td> This expression ;">(.*?(?=<br>)) will return the following match: ACETYLCYSTEINE...

How to select a random row with a group by clause?

mysql,sql,random,order,group
I have the following table SQLFiddle What I'm attempting to do is to select three random images but to make sure that no two images have the same object, what I attempted to do is to do a GROUP BY along with an ORDER BY rand() but that is failing...

Defining groups within an interval

group,stata
In Stata with the following data ID Date 1 1/1/2010 2 1/1/2010 3 1/4/2010 4 1/5/2010 5 1/8/2010 6 1/10/2010 7 1/11/2010 I am trying to create a variable Dummyi that gives a unique variable to all of the IDs that occurred within three days (before or after) of the...

Using Count and date

sql,sql-server,count,group
I have the problem where I need to select records as this: If the # of Job "Plumbers" > 3 (Per House) , return only 03 records, with the plumbers order by "hire date". If there are more than 03 records per "House", I need to return ALWAYS 03 records...

Array create group on the basis of particular field value

php,arrays,group,element
I have following array array ( [0] => Array ( [market_id] => 10 [competition_id] => 31 ) [1] => Array ( [market_id] => 10 [competition_id] => 31 ) [2] => Array ( [market_id] => 11 [competition_id] => 31 ) [3] => Array ( [market_id] => 11 [competition_id] => 31 )...

r count values shared between groups

r,count,group,shared
Here is some dummy data: class<-c("ab","ab","ad","ab","ab","ad","ab","ab","ad","ab","ad","ab","av") otu<-c("ab","ac","ad","ab","ac","ad","ab","ac","ad","ab","ad","ac","av") value<-c(0,1,12,13,300,1,2,3,4,0,0,2,4) type<-c("b","c","d","a","b","c","d","d","d","c","b","a","a") location<-c("b","c","d","a","b","d","d","d","d","c","b","a","a") datafr1<-data.frame(class,otu,value,type,location) I want to get rid of any OTU if any replicate within the group 'location' and 'type' is 0, because I am interested in OTUs...

multiple group by in elasticsearch including missing values

php,elasticsearch,group,kibana
I'm trying to do a group by in elasticsearch, by multiple fields. I know that nested aggregation exists, but what I want is including in a certain bucket the record for which the field I'm grouping by is empty. Say that we have this kind of data structure: SONG_ID |...

MySQL: Count same entries per day

mysql,count,group
in my table I got the following data: date, playerid 2015-05-05, 1 2015-05-05, 1 2015-05-05, 1 2015-05-05, 2 2015-05-05, 2 2015-05-06, 1 2015-05-06, 1 2015-05-08, 1 2015-05-08, 2 Now I would like to count the same entries (player-id) per day, so the result should look like this: date, playerid 2015-05-05,...

Can we improve on my code to swap adjacent array elements in Scala?

arrays,scala,group,swap
I'm learning Scala by working the exercises from the book "Scala for the Impatient". One exercise asks that: Write a loop that swaps adjacent elements of an array of integers. For example, Array(1, 2, 3, 4, 5) becomes Array(2, 1, 4, 3, 5) I did it in 3 different ways,...

How to stop SUM function getting called for each row MySQL pivot

mysql,group
I have a database with 2 tables: 1 for customer orders and another one for customer returns. Both tables have a customer id column and a total column. I'm trying to make a pivot table where I subtract total returns from total orders. The problem is that when there are...

T-SQL Count all rows and group by id

sql,sql-server,group,average
i have a little problem with sql. I need help by a query where is can count all rows and group by the id. I need this, because i need to get the average of logins. Table have this: MRr, date MNr 3 => 5 entries MNr 4 => 2...

How to retrieve the most present pair in groups of three columns, with MySQL?

mysql,count,group
I am working on ice hockey software: trying to find out who in your team has collected the most points with a specific player (in this example user_id = 1). Data structure: goal_user_id | assist_user_id | second_assist_user_id ----------------------------------- 1 | 13856 | null 1 | 15157 | null 1 |...

How to get grouped facet result from Amazon CloudSearch with structured query

amazon,group,facet,amazon-cloudsearch
I am trying to get grouped facet information in following situation : When query requests cars with certain makes (e.g) HONDA or MAZDA), with make and model facet information then query would be like q={or "make":"HONDA" "make":"MAZDA"}&facet.make={}&facet.model={} Then, its facet result would be like: "make" : { "buckets" : [{...

ms-access Group BY a match between several fields

sql,ms-access,duplicates,group
i have a table like: | id | field1 | field2 | field3 | --------------------------------------------- | 1 | A | B | C | | 2 | E | F | G | | 3 | H | A | I | | 4 | *null* | J | K...

How to find Wifip2p groups in android

android,group,wifi-direct
I'm trying to use WiFi-Direct for connecting multiple devices over wifi in a master-slave style (one to many)- one client creates a group using the "createGroup" function, and all the other clients should connect to the group (manually). when a client press on a "Discover peers" button, i want to...

jQuery get index from different element group

jquery,indexing,group
I have list of li that contains 2 group of data, data-type='a'/data-type='b', and order of a/b is random. How do I get index when user clicks on li only based one of the groups, for example, 3rd li clicked, would return index 1 with html below. <li> <div class='img' data-type='a'>...

Merge multiple records in single row

sql,oracle,oracle11g,null,group
I am trying to get two separate records to display on a single line, but keep getting multiple lines with nulls. I thought that if I grouped by Test_Date, I'd be able to get a single row for each test date, with the scores on a single line, but as...

Group array by common id and date and sumarize to calendar table

php,arrays,date,sum,group
I've been ripping my hair out on this one. Struggling with understanding how i really want to attack this problem, even the basic logic... I've got this dataset: Array ( [0] => stdClass Object ( [id] => 233773869 [pid] => 9919304 [tid] => 6754304 [uid] => 1502708 [project] => **HIDDENNAME**...

Difference between Pane and Group

javafx,group,pane
My question is simple : in JavaFX, what is the difference between a Pane and a Group ? I can't make any difference ... Thank for your answer...

Subquery in SUM

mysql,sql,sum,group
I am using MySQL and I have two tables. One has the reference to the values and the other has the real values. I want to calculate the SUM. ItemMess +----+--------+----------+---------------------+ | ID | ItemID | MessType | TimeStamp | +----+--------+----------+---------------------+ | 1 | 2 | 1 | 2015-04-26 18:53:33...

Mysql conditional count with group by in where clause

mysql,sql,group
I have a simple messaging system - keeping all the messages in a single table. Each message can(and should) be associated with one of the 3 other tables, that represent some sections of the website. Here is the create table statement CREATE TABLE `messages` ( `id` bigint(20) unsigned NOT NULL...

mysql Output data from two tables using most recent entry

php,mysql,sql,group,union
I have done a good search for a similar question, but with no joy. I think the answer to my question is based around DISTINCT, GROUP and UNION, but just can't put the together in any way which makes sense. I have 2 tables: users(id, username) activitylog(id, userid, usernamedisp, activity)...

conditional grouping and summarising data frame in [R]

r,group,dplyr
I have a data frame like this: df <- data.frame(ID = c("A", "A", "B", "B", "C", "C"), time = c(3.1,3.2,6.5,12.3, 3.2, 3.4), intensity = c(10, 20, 30, 40, 50, 60)) |ID | time| intensity| |:--|----:|---------:| |A | 3.1| 10| |A | 3.2| 20| |B | 6.5| 30| |B | 12.3|...

SQL: Select new columns based on group order

sql,sql-server,group-by,sql-order-by,group
I went through many questions on this site but wasn’t able to find solution. I’ve got a table: Date GroupID CHANNEL 24/02/2015 1 A 26/02/2015 1 B 27/02/2015 1 C 21/03/2015 2 D 20/02/2015 3 E 25/02/2015 3 D 28/02/2015 4 C 04/03/2015 5 B 05/03/2015 5 E 10/03/2015 5...

How to use group by sqlite query in Android

android,sqlite,table,group
In sqlite the group by query works...but in android the query doesn't work...how to use group by query in android. The error says: Syntax error,Delete this token(Group by bname), SELECT boname,bname,SUM(amount) FROM Auction where boname ="+boatno.getText().toString() Group by bname,null) protected void adddata1() { Database db=new Database(getActivity()); SQLiteDatabase sb=db.getReadableDatabase(); Cursor cus=sb.rawQuery("SELECT...

PSQL group by rows into multiple groups

sql,postgresql,group-by,group
I have a table id index value 1 1 2 2 1 3 3 2 6 4 3 8 I can do like this: select sum(value) from table group by index But what I want is that each row can go to multiple groups, pseudocode select sum(value) from table group...

Order categories and subcategories in one table mysql

mysql,sql,order,group,categories
I have a category table like this: categories: id, name, parent_id How can I order categories? Sample: Men Top Shirts Tshirts Bottom Jeans Women Top Jackets Tshirts Bottom Jeans Accessories Belt Cap ...

Angular - ng grid select next/previous item grammatically with grouping

javascript,angularjs,events,navigation,group
I'm trying to navigate between the ng-grid entities(rows) using next and previous buttons while the grid has grouping. The problem occur when I'm clicking on the next/previous action, instead of selecting the actual next item inside the group -> the next element from the grid configuration is being selected! I've...

how to unique a data frame by the values in a specified column?

r,max,group
I have a data frame in R with columns "name" and "length". The "name" is not unique and the same "name" repeats several times in the data frame. But I wanted to keep only one row with the largest "length" for each "name". Which function in R can I use...

Groupby without using underscore js

javascript,jquery,group
I have a collection which is group by ID. Each id contains array of objects. I want to loop through it and create a target collection which will be group by "Id" column as shown on the example. I will not use underscore js. I have to use javascript reduce...

Grouping by similar categoies over time sql

sql-server,sql-server-2008,group-by,group,aggregates
I looked around for awhile, but couldn't find anything. I have a table that looks like this: DATE | Shift | Parts Used 1/1/15 1:15.....1........1 1/1/15 2:06.....1........2 1/1/15 3:45.....1........3 1/1/15 7:33.....2........1 1/1/15 8:14.....2........2 1/1/15 9:00.....2........3 1/1/15 23:01....1........1 1/1/15 23:55....1........2 I would like to group by each individual shift. UNFORTUNATELY shift...

Column operations on pandas groupby object

python,pandas,group
I have a dataframe df that looks like this: id Category Time 1 176 12 00:00:00 2 4956 2 00:00:00 3 583 4 00:00:04 4 9395 2 00:00:24 5 176 12 00:03:23 which is basically a set of id and the category of item they used at a particular Time....

MongoDB aggregate group multiple fields

mongodb,group,project,aggregate
Given the following dataset: { "_id" : 1, "city" : "Yuma", "cat": "roads", "Q1" : 0, "Q2" : 25, "Q3" : 0, "Q4" : 0 } { "_id" : 2, "city" : "Reno", "cat": "roads", "Q1" : 30, "Q2" : 0, "Q3" : 0, "Q4" : 60 } { "_id"...

MongoDB Aggregation $group needs an array for _id but $out won't handle it

mongodb,group,aggregation
I need to sum the number of occurrences of an array. I need to output this to a collection but when I try and use the $out keyword, it fails with "can't use an array for _id\" Is there any way to project the value of the _id field from...

how to get regex 'or groups' like (foo|bar) working with find -regex? (OS X)

regex,osx,find,group
Suppose I want to find all .jpg and .png images, using a regex, I'm trying this: find . -regex ".*\.(jpg|png)" But it doesn't work (no results, even though there are jpg and png files present). Now, if instead of the (jpg|png) part I just use jpg or png, it works...

Create Subtotal Rows from Group but Remove the detail rows via TSQL

sql,tsql,group,aggregate-functions,subtotal
I basically have: select a,b,c,d,e from table1 I need the subtotal of e where c and d are the same. I suppose we can do a group by c and d but will run into a "..not part of aggregate function" issue for columns a and b are not in...

Form does not validate in Django

django,forms,validation,user,group
I have such a form as shown below. When I click the "Add" button instead of the notification that the fields are required I get an error: DoesNotExist at /users/add-to-group/ Group matching query does not exist. My form code class AddUserToGroupForm(forms.ModelForm): group = forms.ModelChoiceField(queryset=Group.objects.all(), required=True) user = forms.ModelChoiceField(queryset=User.objects.all(), required=True) class...

SQL : Grouping the Data

sql-server,case,group
CREATE TABLEsample ( Term NVARCHAR(100), Year NVARCHAR(50), Location NVARCHAR(100) ); INSERT INTO sample VALUES('1','1997','New York'); INSERT INTO sample VALUES('1','1997','New York'); INSERT INTO sample VALUES('1','1997','New York'); INSERT INTO sample VALUES('1','1997','London'); INSERT INTO sample VALUES('1','1997','London'); INSERT INTO sample VALUES('1','1996','London'); INSERT INTO sample VALUES('1','1996','London'); INSERT INTO sample VALUES('1','1998','New York'); INSERT INTO sample VALUES('1','1998','New...

Gaps and Islands solution in Oracle - use of recursive

oracle,plsql,group
I have a problem that could be easily solved using curser in Oracle. However, I wonder if that could be done using select only. I have 1 data set that contains the following fields: Start, Description, MaximumRow, SequentialOrder. The data set is ordered by Description, Start, SequentialOrder. This is the...

Plotting Pandas groupby groups using subplots and loop

python,pandas,plot,group,subplot
I am trying to generate a grid of subplots based off of a Pandas groupby object. I would like each plot to be based off of two columns of data for one group of the groupby object. Fake data set: C1,C2,C3,C4 1,12,125,25 2,13,25,25 3,15,98,25 4,12,77,25 5,15,889,25 6,13,56,25 7,12,256,25 8,12,158,25 9,13,158,25...

insert a group of rows to a table in PostgreSQL

postgresql,insert,group,rows
i have a table with a lot of rows and i want to create a new table and copy just a bunch of rows (like 30) in my new table.... - the table name is account (code,code_activation,email,password) and i'm using PostgreSQL. and thanks in advance.

SQL Grouping subsequent dates into bins

sql,sql-server,sql-server-2012,group,lead
Assuming I have the following table: date version 2015-02-01 v1 2015-02-02 v1 2015-02-03 v1 2015-02-04 v1 2015-02-02 v2 2015-02-03 v2 2015-02-08 v1 2015-02-09 v1 My query shall group dates in such way I get this result: datefrom dateto version 2015-02-01 2015-02-04 v1 2015-02-08 2015-02-09 v1 2015-02-02 2015-02-03 v2 I tried...

How to group MySQL query by multiple criterias?

mysql,sql,group-by,group
here's what I'm trying to achieve. I have this table: Table 'Receipts': Fruit |Receipt| Name | No | --------|-------|------- Apple | 534 | Mike Apple | 422 | Mike Apple | 355 | Mike Peach | 646 | Robert Banana | 412 | Alex Banana | 124 | Alex Banana...

Lambda Linq Iqueryable group - add another grouping

c#,linq,lambda,group,iqueryable
I have a method that I use for generating a summary report, based on the options a user selects in pick lists, to count the number of a type of test that is completed in a region, with subset locations, within a date range. Here's what the data looks like:...

How to group a list of grouped lists? C#

c#,linq,list,group
I need a grouped list of grouped lists; I have a bunch of articles that I need to group by year, and group by month within each year. It will look something like this on the page: 2015 February Article 1 Title Article 2 Title January Article 3 Title 2014...

How to group related .tif files?

python,group,tiff,itertools
I am attempting to group related files associated with a .tif image. You can see from the list that there are 7 related files per group. I am looking for a way to group these files so that I can move them via shutil.move() into various folders. The following script...

grouped sql query (mysql) - order by

mysql,group
Lets's say i have a table sign_ins which has data like so: (the real table has 3.5 million rows) +-----------+---------+------------------+ | school_id | user_id | date(created_at) | +-----------+---------+------------------+ | 1 | 4 | 2009-04-20 | | 1 | 4 | 2009-04-21 | | 1 | 4 | 2009-05-06 | |...

Crystal reports group selection sorting

parameters,crystal-reports,report,group
I am working on a report that has two parameters that gives the user the ability to sort the records. One being the salesman and the other being the company code which is just the first three letters of the company name. They want the ability to sort these records...

MySQL multiple join and grouping

mysql,sql,join,group
I have three tables that I'm trying to create a view. The three tables are, news ---------|---------| newsID | title | ---------|---------| 1 | title1 | 2 | title2 | 3 | title3 | ---------|---------| comments -----------|----------|-----------| commentID | newsID | comment | -----------|----------|-----------| 1 | 1 | | 2...

libGdx - Scaling group doesn't affect children

java,libgdx,group,actor
I have a group and actors inside of it. I add moving and scaling actions to whole group. Moving works great but I have a problem with scaling - it doesnt affect children. I think there is something wrong with drawing method in my group class but I cant figure...

group by alias Oracle

sql,oracle,oracle10g,group
Hello all, please help me with this. I need get all state (1,2,3,4) with out dupicate. 1 xxx 2 yyy 3 zzz 4 jjj My first and only idea was get all state and group them: select state1 as state,desc1 as desc from table where id=X Union select state2...

Oracle SQL Group By, use value from latest date

sql,oracle,group
Basically, I'm looking to count the matching "group by" records where the most current value in a field, for that group, is equal to a requested value. So, for example, let's say that I have: A, B, 2, 1/1/2015 E, F, 9, 12/1/2014 A, B, 6, 1/15/2015 E, F, 4,...

SQL SELECT COUNT GROUP BY - error

mysql,sql,count,group
I am having a problem with my sql statement, I have two tables (ogrenci and taksit). I am trying to count the number of taksits where they are zero and group them by KategoriID.KategoriID is both in ogrenci and taksit tables while odendi is only in taksit table. I could...

Grouping Data Base on Reference Table

mysql,group
Data for province table: idProv Province 1 JT 2 JB 3 BT Data for City table: idCity IdProv City 1 1 BL 2 1 ML 3 1 MD 4 2 CB 5 2 TM 6 3 YK 7 3 SM Data for data table: idData idCity population data1 data2 1...

Group By MySQL query to ignore null and pull last value

mysql,null,group
I'm trying to find a way to write a query that will group a ID's together and display output of the latest data removing NULLs for the previous grouped ID's data. For example: ID | ID2 | ColA | ColB | ColC --------------------------------------------------- 1 | 1 | ABCD | XY...

How do I group only the last `n` rows?

mysql,sql,group,mariadb
Take the following table: id - member_id - day 0 1 1 1 1 1 2 1 2 3 2 2 4 1 3 5 2 3 6 2 3 7 1 3 8 1 3 9 2 3 Lets say I want to do something like: SELECT `day`, COUNT(`id`)...

LEFT JOIN - Sort and Group

php,mysql,sorting,left-join,group
I get only one row of the elements and the matching categories. $stmt = $conn->prepare("SELECT lt_category.id, lt_category.title, lt_category_elements.category_id, lt_category_elements.title as elementitle, lt_category_elements.text FROM lt_category LEFT JOIN lt_category_elements ON lt_category.id = lt_category_elements.category_id"); category 1 element1 (is there) element 2,3,4,5 (is missing) etc. category 2 element1 (is there) element 2,3,4,5 (is missing)...

How to achieve MySQL Query combining multiple COUNT() and GROUP BY

mysql,sql,select,count,group
So I have this type of data: id date user_id result 1 2015-05-04 1 win 2 2015-05-06 1 loss 3 2015-05-09 2 loss 4 2015-05-10 2 win 5 2015-05-16 1 win I need to get the top 4 users sorted by most wins. But I also need to get the...

Assign rows to a group based on spatial neighborhood and temporal criteria in R

r,for-loop,group,spatial,temporal-database
I have an issue that I just cannot seem to sort out. I have a dataset that was derived from a raster in arcgis. The dataset represents every fire occurrence during a 10-year period. Some raster cells had multiple fires within that time period (and, thus, will have multiple rows...

Echo DISTINCT row to remove duplicate results MYSQL

php,mysql,duplicates,group
I have the following code, works great: /////////////////////// $todo=$_POST['todo']; if(isset($todo) and $todo=="search"){ $species=$_POST['species']; $lab_section=$_POST['lab_section']; $search_text=$_POST['search_text']; $type=$_POST['type']; $query="select * from mytable where "; if(strlen($species) > 0 ){ $query.= " species='$species' and "; } if(strlen($lab_section) > 0 ){ $query.= " lab_section='$lab_section' and "; } ////////////////////////// Key word search query ///////// $search_text=ltrim($search_text);...

How to check if a group exists and add if it doesn't in Linux Shell Script

linux,shell,ubuntu,user,group
this is a summary of what i want my code to do: if (group exists) then (add user to group) else (create group) (add user to group) fi I am using the Ubuntu virtual machine but all of the results i have found on similar sites do not work....

Generating report directly from Mysql Query data (using groupby, count)

php,mysql,sql,group,aggregate-functions
I have two tables for storing image and its related exif data: Image table has records like below: (query: select * from image_table where order_id = 3030303) Image_Exif_Info table has records like below: (query: select * from image_exif_info where image_id in (select image_id from image_table where order_id = 3030303) As...

How to get certain information out of arraylist grouped into other lists in Java

java,arraylist,text-files,group,information-retrieval
I wrote a program, that reads multiple (similar) textfiles out of a Folder. Im splitting the information by space and store everything in one arraylist which contains data kind of this: key1=hello key2=good key3=1234 ... key15=repetition key1=morning key2=night key3=5678 ... Now I'm looking for a way to get those information...

Python regex inconsistent output between groups() and group()

python,regex,group
I am doing a little test to grab backslash (\) using Python regex and what I found is a bit strange. import re stringing = "\\" pattern = re.compile(r'(\\)') search = pattern.search(string) print search.group() The output is shown below, which is as expected \ However, when I use .groups() as,...

How to Compare Column to Count in a Query

sql,count,ms-access-2010,group
I'm not too sophisticated with SQL, I don't know how to compare a count back to a column I'm selecting in a Query in Access. One column is generated as a count that counts IDs, but I want to verify it's correct (compare the column GroupCount with a SQL Count...

Order Mysql query by Name and other fields PHP

php,mysql,sorting,group
I have a question about MySQL. I have a Table with this fields: WorkerName Date HoursWorked Ok, if I do this Query: SELECT WorkerName, Date, HoursWorked, SUM(HoursWorked) FROM myTable GROUP BY WorkerName I have the field grouped by the Worker Name BUT with a only row. I want to show...

Java regex to match absent groups at fixed locations

java,regex,pattern-matching,group,matching
A regex is needed that always matches (with matches(), not find()) and always recognizes 3 groups, for 3 different cases of input, like 1234 ab$.5!c=:d6 efg(789) 1234 efg(567) efg(567) The pattern (?:^(\d+)\s+(\S)\s)?\s*([^\(]+\(\S+\)) represents the kind of values expected in each group (without assumptions about the location of characters), but only...

C# linq group By on field and result string? [closed]

c#,linq,dynamic,expression,group
how to write dynamic groupby with selectfieldString and resultFieldString? sample: public class Customer { public int Id; public string Name; public string LastName; public decimal Amount; } var lst = new List<Customer>(); lst.Add(new Customer { Id = 1, Name = "vahid", LastName = "Aghilpour", Amount = 15 }); lst.Add(new Customer...

Regex closest text matching [duplicate]

regex,match,group,closest
This question already has an answer here: Regular expression to stop at first match 4 answers I have string like below. I can't match closest group. I want to extract "text" word. Text Example: some string foo text doo foo doo some string I'm using this pattern. (foo)([\s\S]+)(doo|some) This...

Send a success signal when the group of tasks in celery is finished

django,signals,task,group,celery
So i have a basic configuration django 1.6 + celery 3.1. Say i have an example task: @app.task def add(x, y): time.sleep(6) return {'result':x + y} And a function that groups and returns job id def nested_add(x,y): grouped_task = group(add.s(x,y) for i in range(0,2)) job = result_array.apply_async() job.save() return job.id...

how to sum up by hour in mysql

mysql,sql,group
For example, I have a table1(This is just a part of table1,table1 actually have 57000 records, starttime ranges from 2014-04-08 23:59:56 to 2014-04-09 23:59:56 ): +---------------------+ | StartTime | +---------------------+ | 2014-04-08 23:59:56 | | 2014-04-08 23:59:59 | | 2014-04-09 00:00:03 | | 2014-04-09 00:00:03 | | 2014-04-09 00:00:05 |...

When using an aggregate function in SQL, will the associated columns be selected?

sql,group,aggregate-functions
I have the following query SELECT day, category_id, name, qval MIN(CONCAT(category_id, qval)) FROM facts WHERE day = CURDATE() GROUP BY category_id Will the name that gets selected always be the name associated with the MIN record that is identified?...

Group By Date and SUM int - Date formatting and Order

sql-server,date,casting,order,group
I'm trying to get the SUM of the quantity sold on a day. I need the results to be in ORDER BY date. The query below gives me the exact result I need, except the date is not formatted to what I need. SELECT CAST(Datetime AS DATE) AS 'date', SUM(quantity)...

SQL: Query to merge (some) rows

sql,oracle,merge,sum,group
I'm currently trying to create a query that merges some rows to one category and sums up the related values. I'll try to illustrate it with the following example: Country | Sales Jan | Sales Feb | Sales Mar --------+-----------+-----------+---------- Austria | 100 | 110 | 120 Spain | 120...

GROUP BY Latest row

php,mysql,sql,order,group
I want to return only the newest rows that have a different video_id. I have been having trouble getting this to work no matter which way I try it... I have done this before and it isn't that difficult but for some reason my particular query will not work. My...

Group query results by “today”, “in last 7 days”, “in last month” and “older”

mysql,sql,database,group-by,group
I have a simple question related to grouping rows by date with some "narrative" periods. Let's assume that I have very simple table with articles. ID which is PK, title and date. The date column is datetime / timestamp. I would like to group somehow my results so I can...

SQL grouping results by first date of the week

sql,sql-server,date,group
Currently writing an sql query on sql server 2008 and have a query which counts the amount of sales in a week, currently my code is grouping by week number however I am wanting to return the first date in the week. currently it's returning week number count 1 5...

group on mongodb filtering by any field

node.js,mongodb,express,mongoose,group
I am trying to make a group query on mongodb (using mongoose) filtering by any other different field than the group criteria. I have this by the moment: usersDB.aggregate().group ( {_id: '$residence', total: { $sum: 1 } } ).exec(function (err, result) { if(err) res.send(err); else res.send(result); }); And it works......

Multiple radio button groups in one form

html,forms,group,radio
is it possible to have multiple radio button groups in a single form? Usually selection one button deselects the previous, I just need to have one of a group deselected. <form> <fieldset id="group1"> <input type="radio" value=""> <input type="radio" value=""> </fieldset> <fieldset id="group2"> <input type="radio" value=""> <input type="radio" value=""> <input type="radio"...

Calculate extra column in group by

sql-server,sql-server-2005,group
In sure this should be simple, but I'm having a brain fart over it. In SQL Server 2005, how do you add an "extra count" to a GROUP BY query? Consider the following... ;WITH DATA AS ( SELECT 1 AS ID, 1 AS TYPEID, 0 AS ACTIONNEEDED UNION SELECT 2...

Javascript Look behind replace all occurences

javascript,regex,replace,group
I want to replace all occurences of .digit with 0.digit. I'm new to regular expressions but as far as I understand I could use look behind to do this. But JS does not support that, I'd like to know if someone knows a solution. To show the problem i wrote...

R Merge rows in same data frame based on common values

r,merge,group,dplyr
Most of the approaches I've come across involve using dplyr to apply a function when combining features, however, I would just like to restructure a single data frame without applying any function to each group. I have a single data frame that looks like this: gene_name chr nb_pos nb_ref nb_alt...

django get latest for each group, group by foreign key

django,count,group
Assume I have something like these models: class Product(models.Model): name = models.CharField(max_length=50) class Sale(models.Model): product = models.ForeignKey(Product) sale_date = models.DateField() I want to get the latest sale for each product. Latest means the latest sale_date. Also, in the same query I want to get the number of products sold for...

group by time interval

sqlite,group
Assume I have a table like how can I create a table like where the groups are created of timeintervals with the length of 1 second. Thank you in advance!...

Having clause does not work [duplicate]

sql,group,having
This question already has an answer here: Retrieving the last record in each group 13 answers I am beginner with SQL, i'm currently trying to use the HAVING CLAUSE but it does not work.. I have two tables : tchat : tchat_message : So i want the lastest messages...

Group json object in javascript

javascript,json,group
I want to group json array by first letter This is my data records it quesry from sqlitedb Ex : [ {"pid":2,"ID":1,"title":"aasas as"}, {"pid":3,"ID":2,"title":"family"}, {"pid":4,"ID":3,"title":"fat111"} ] I need this output { A: [{ title: "aasas as", ID: 1 }], F: [{ title: "family", ID: 2 }, { title: "fat111", ID:...

Group every n-th element of array

ruby,arrays,group-by,group,grouping
I have an array: array = [1, 2, 3, 4, 5, 6, 7, 8, 9] How do I group every n-elements of array? For example, for 3: [[1, 4, 7], [2, 5, 8], [3, 6, 9]] I wrote this code, but it's ugly: array.each_with_index.group_by { |e, i| i % 3}.map...

Combine two queries in Oracle

sql,oracle,group,union
I have 2 queries to retrieve faultCount and responseCount as follows and it works fine. select count(*) as faultCount, COMP_IDENTIFIER from CORDYS_NCB_LOG where AUDIT_CONTEXT='FAULT' group by COMP_IDENTIFIER order by responseCount; select count(*) as responseCount, COMP_IDENTIFIER from CORDYS_NCB_LOG where AUDIT_CONTEXT='RESPONSE' group by COMP_IDENTIFIER order by responseCount; I need to join to...

php to json group array

php,mysql,json,group
my goals is list singers and click singer show singers songs. this is my php <?php $server = "localhost"; $username = "user"; $password = "123456"; $database = "database"; $con = mysql_connect($server, $username, $password) or die ("Could not connect: " . mysql_error()); mysql_select_db($database, $con); mysql_query("set names 'utf8'"); $sql = "SELECT a.singername,b.songname,b.songembeded...

Mongodb Group by count Based on Array fields

mongodb,group,aggregation
I am having following data . I want to group by fields in array . { "_id" : ObjectId("54e73137758646882f445383"), "items" : [ { "name" : "one", "quality" : "high" }, { "name" : "one", "quality" : "low" }, { "name" : "two", "quality" : "high" } ] } /* 1...

Show entire record from table with minimum timestamp in a group

sql,group
I have been trying for about three hours to solve this problem but cannot find the solution. How would I show the entire row (all 20 columns) for the first occurance (minimum time) of each name in my table? For example, I would like to do something like this, which...

MySQL - help writing group query

mysql,sql,subquery,group,aggregate
Here are my tables: Teacher: Student: Test a teacher has students, a student takes tests. SELECT t.name as teacherName, s.name as studentName, t.id as teacherID, s.id as studentID, MIN(tt.grade) as grade FROM teacher t JOIN student s ON s.`teacher_id` = t.id JOIN test tt ON tt.student_id = s.id GROUP BY...

How do you get an integer number for an item in group in SQL?

sql,sql-server-2008,count,group
I have two tables in a SQL Server 2008 database, one listing groups and another mapping those groups to records for objects. One group may have many objects. I've got the following query SELECT GroupNumber From dbo.Groups G LEFT OUTER JOIN dbo.Mapping_ObjectToGroup m ON G.GroupID = m.GroupID Which results in...

How to do it without the while loop in sql

sql,sql-server,group
I have a table like this, A | B ---------------------- 1 | 10 1 | 20 2 | 30 2 | 40 I need output as, A | B ------------------------ 1 | 10,20 2 | 30,40 Thank you in advance...

fabricjs How can i keep fixed size on group elements while others scaling?

javascript,frameworks,html5-canvas,group,fabricjs
Hello i use fabricjs to play with the html canvas. I create the canvas and i add group of objects on it. On a group of objects , i need to keep fixed width & height for some objects while i scale the object. I use the 'object:scaling' event to...

SQL - Subtraction of values based on IDs and group after

sql,oracle,group,subtraction
I'm using Oracle. Having a table as: Year Type Value 2011 1 500 2011 2 550 2011 3 600 ... ... 2012 1 600 2012 2 750 2012 3 930 I need to subtract all the values from different types, grouped by year. The operation would be: For 2011 ->...

How to avoid different capture group numbers in a regex?

regex,if-statement,group
I'm trying to capture an IP address in a log and revert on a hostname if the address is 0.0.0.0. Here are some examples of logs: Foo bar ip=0.0.0.0 baz host=YOLO-PC foobar bazinga In this case, I want "YOLO-PC" because IP is 0.0.0.0 Foo bar ip=12.23.34.45 baz host=FOOBAR-PC foobar bazinga...