group-by

How to use GROUP BY on a CLOB column with Oracle?

家住魔仙堡 提交于 2019-12-22 04:07:24
问题 I'm trying to combine the GROUP BY function with a MAX in oracle. I read a lot of docs around, try to figure out how to format my request by Oracle always returns: ORA-00979: "not a group by expression" Here is my request: SELECT A.T_ID, B.T, MAX(A.V) FROM bdd.LOG A, bdd.T_B B WHERE B.T_ID = A.T_ID GROUP BY A.T_ID HAVING MAX(A.V) < '1.00'; Any tips ? EDIT It seems to got some tricky part with the datatype of my fields. T_ID is VARCHAR2 A.V is VARCHAR2 B.T is CLOB 回答1: I'm very familiar with

SQL Group By - counting records per month/year, error on insert - NOT A VALID MONTH

会有一股神秘感。 提交于 2019-12-22 04:03:15
问题 I have this example data: Country | Members | Joined USA | 250 | 1/1/2012 USA | 100 | 1/8/2012 Russia | 75 | 1/20/2012 USA | 150 | 2/10/2012 When I query this data I would like to aggregate all the records in a given month. The result of the query would look like: Country | Members | Joined USA | 350 | 1/2012 Russia | 75 | 1/2012 USA | 150 | 2/2012 As a select that is simple enough: select country, count(*) as members , to_char(trunc(joined), 'MM-YYYY') from table group by country, to_char

Entity Framework skip take by group by

大兔子大兔子 提交于 2019-12-22 04:02:14
问题 I a currently "paging" through a table ("Table1") that has the following fields { Policy, Name, Amount, Date} and there can be mulitple records in "Table1" for a policy, like the following: return context.Table1s.Orderby(i => i.Policy) .Skip(endingRecord).Take(page) .ToList(); How would I do this if I wanted to first group by Policy and then skip and take on the distinct policies (basically trying to ensure that a "page" contains all the records for the policies included in the page)? I'm

MySQL Query to group by date range?

眉间皱痕 提交于 2019-12-22 03:52:35
问题 I've got a table in MySQL that shows me number of hours logged on a daily basis. I'm trying to build a view that will allow me to quickly group my data by blocks/range of days. The simplest case would be on a monthly basis which wouldn't be difficult. I could just select the date as "%y-%m" and then group by that column. Ex: select time_logged, date_format(start_date, '%Y-%m') AS `month_logged` from work_log group by month_logged That works fine if I am just grouping by month. But my issue is

Fetch cumulative sum from MySQL table

こ雲淡風輕ζ 提交于 2019-12-22 00:33:08
问题 I have a table containing donations, and I am now creating a page to view statistics. I would like to fetch monthly data from the database with gross and cumulative gross. mysql> describe donations; +------------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | transaction_id | varchar(64

Slick 2.1.0 Filter Max Version in a Table

那年仲夏 提交于 2019-12-22 00:29:17
问题 I'm trying to get the max version number from a table. My table contents are: id externalId name version 1 10 n1 1 2 65 n2 2 3 10 n3 2 4 77 n4 1 In the table above, we have rows that has the maximum version as 2, so my query has to return this maximum version row for the given externalId that I pass into my query. I'm now stuck up with writing the Slick version of it. Any suggestions, pointers? This is what I have so far: (I pass in the externalId) for { myTable1 <- myTable1Elems if myTable1

Complex join with nested group-by/having clause?

孤人 提交于 2019-12-22 00:06:08
问题 I ultimately need a list of "import" records that include "album" records which only have one "song" each. This is what I'm using now: select i.id, i.created_at from imports i where i.id in ( select a.import_id from albums a inner join songs s on a.id = s.album_id group by a.id having 1 = count(s.id) ); The nested select (with the join) is blazing fast, but the external "in" clause is excruciatingly slow. I tried to make the entire query a single (no nesting) join but ran into problems with

Group by and filter XML data with XSL

我的梦境 提交于 2019-12-21 23:12:29
问题 I have the following XML code: <root> <options> <companies> <company url="http://www.brown.com">Brown LLC</company> <company url="http://www.yellow.com">Yellow LLC</company> <company url="http://www.black.com">Black LLC</company> <company url="http://www.bourdeaux.com">Bourdeaux LLC</company> <company url="http://www.orange.com">Orange LLC</company> </companies> </options> </root> and I need to do two things with it: Build a html dropdown with the unique first letters found in the company

Group list of tuples efficiently

有些话、适合烂在心里 提交于 2019-12-21 22:26:40
问题 I have a large list of tuples e.g. [ (1,2), (1,3), (1,4), (2,1), (2,3) ] etc. I want to convert it to [ (1, [1,2,3,4]), (2, [1,3] ) ] efficiently. I am grouping tuples by the first element of each tuple i.e. (1,2), (1,3), (1,4) becomes (1, [2,3,4]) (also see the Haskell version below). I doubt that this can be done in one pass? The input list is always ordered. In python in tried using defaultdict which I thought was the natural solution without reinventing the wheel. It works well but it

Multiple PIVOTS? Need to count by Hour Per Month

感情迁移 提交于 2019-12-21 20:59:54
问题 This should be pretty simple. I have other PIVOT SQL queries working fine. I want to count logins: by hour, by month. I am thinking two PIVOTs or UNPIVOT and then PIVOT? Yes, I have dug around here, other sites, Google, etc. I am pretty stuck. SELECT loginid ,DATEPART(MONTH,logtime) Month , DATEPART(HOUR, logtime) Hour FROM somelog (nolock) ) temp PIVOT ( COUNT(loginid) FOR Month in (JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC) ) AS Pvt What I want the results to be.. HOUR,JAN,FEB,MAR 00