group-by

Error: column “this_.phitorsionangle” must appear in the GROUP BY clause or be used in an aggregate function

喜欢而已 提交于 2019-12-13 15:16:03
问题 I'm having some trouble with an sql query. I'm using Hibernate Criteria to build the query. I create some bins from a database by rounding the values with certain intervals (the binSize) and then grouping them. This works great when I try it directly in SQL with the query: SELECT floor(phiTorsionAngle / 2) * 2 as phiTorsionAngleBin, floor(psiTorsionAngle / 2) * 2 as psiTorsionAngleBin, floor(phiTorsionAngle / 2) + 180 as phiTorsionAngleBinIndex, floor(psiTorsionAngle / 2) + 180 as

Group By Column Alias

懵懂的女人 提交于 2019-12-13 14:28:59
问题 I want to group an sql statement by a column alias. In essense, I want the below to function as it should logically, but grouping by a column created with an as is not allowed. (Invalid column name). Anyone got any tips? SELECT CASE WHEN Date IS NULL THEN 'EMPTY' ELSE CASE WHEN Date = '1/1/1753' THEN 'UNAVAILABLE' ELSE CAST(MONTH(Date) as varchar(MAX))+ '/'+ CAST(YEAR(Date) as varchar(MAX)) END END AS MonthYear FROM tbltablename GROUP BY MonthYear 回答1: For the immediate problem of the

Group users by age for a range

六月ゝ 毕业季﹏ 提交于 2019-12-13 14:03:11
问题 I have some data which i need to make some statistics. I need to group the users by age. var byAge = displayResult.GroupBy(x => x.Age); Which i can do as above. However, this gives me ages like 19, 20, 21 etc. what I want is grouping age by 10 years, such as users between 10-20 yearsold, 20-30 years old, 30-40 years old etc. How can i get that? 回答1: You can truncate the trailing digit by dividing by ten using integer division, and then multiplying back by ten. var byAge = displayResult

LINQ to XML GroupBy

南楼画角 提交于 2019-12-13 13:12:15
问题 I want to use LINQ to convert input XML to output XML by performing GROUPBY on "Summary" field and SUM up the Balance field. Input XML: <Root> <Account> <Summary>Checking</Summary> <Comprehensive>Interest Checking Account</Comprehensive> <Currency>Dollar</Currency> <Balance>10000000.000000</Balance> </Account> <Account> <Summary>Savings</Summary> <Comprehensive>Market Account</Comprehensive> <Currency>Dollar</Currency> <Balance>20000000.000000</Balance> </Account> <Account> <Summary>Checking<

Pandas temporal cumulative sum by group

♀尐吖头ヾ 提交于 2019-12-13 12:10:20
问题 I have a data frame where 1 or more events are recorded for each id. For each event the id, a metric x and a date are recorded. Something like this: import pandas as pd import datetime as dt import numpy as np x = range(0, 6) id = ['a', 'a', 'b', 'a', 'b', 'b'] dates = [dt.datetime(2012, 5, 2),dt.datetime(2012, 4, 2),dt.datetime(2012, 6, 2), dt.datetime(2012, 7, 30),dt.datetime(2012, 4, 1),dt.datetime(2012, 5, 9)] df =pd.DataFrame(np.column_stack((id,x,dates)), columns = ['id', 'x', 'dates'])

How to group rows with same value in sql? [closed]

寵の児 提交于 2019-12-13 10:53:55
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . How to group rows with same value in sql? data1 123 12/03/2009 124 15/09/2009 data2 333 02/09/2010 323 02/11/2010 673 02/09/2014 444 05/01/2010 回答1: Try this DECLARE @temp TABLE(col1 varchar(20),col2 int, col3 varchar(20)) insert into @temp values ('data1', 123 , '12/03/2009'),('data1', 124 , '15

mySQL Largest number by group

牧云@^-^@ 提交于 2019-12-13 10:53:34
问题 I have messed around with this code for quite sometime. First thing I have my SQL table setup as char instead of decimal because I don't want the number to always show a decimal value unless it has a decimal value (Is there another way to do this?). I change it to decimal within my code but I believe this is where the problem lies. I am trying to pull the largest fish per user per species but it isn't working out. SELECT * FROM (SELECT * FROM entries ORDER BY CAST(weight AS DECIMAL(9,3)) DESC

using group by with specification in Spring data count method

天大地大妈咪最大 提交于 2019-12-13 10:29:40
问题 I want to implement a spring data method which check result of the following query select count(1) from installation_requested_t requested where requested.installation_id in (select installation_id from installation_requested_t where request_id=?) group by requested.installation_id having count(1)>1; For the project, it is mandatory to use specification with the spring data jpa. So there is my repository method call : installationRequestedRepository.count( InstallationSpecs

SQL - Can I have a Group By clause after a nestled Select?

跟風遠走 提交于 2019-12-13 10:22:23
问题 For example: Select max(date) From table A Where max(date) < any (select.. ...) Group By Book_Name,Client_Name So the max(date) field could be compared to the Nestled Select return, as if the grouping of the greater Select was already made. 回答1: What you want is typically done with the HAVING clause. Select Book_Name,Client_Name, max(date) From table A Group By Book_Name,Client_Name HAVING max(date) < any (select.. ...) I removed reference to the other answer. I don't think it was correct and

Select distinct ordered pairs from table join grouped by event's most recent date

ぐ巨炮叔叔 提交于 2019-12-13 10:17:33
问题 Following the post Select distinct ordered pair from table join How can I select the most recent John's joined rows grouped by ordered pair, regardless the order (e.g. John -> Jane or Jane -> John)? First table: table_a +-----------+--------------+-------------------+ | id | name | created_at | +-----------+--------------+-------------------+ | 1 | John |2016-08-26 15:40:21| +-----------+--------------+-------------------+ | 2 | Jane |2016-08-26 15:37:21| +-----------+--------------+ --------