group-by

Conditional aggregate with Group By clause

这一生的挚爱 提交于 2019-12-12 04:55:27
问题 I'm trying to do this with HiveQL but I don't know how to do this in SQL neither. Table structure as follows: id1 id2 category 123 abc 1 123 def 1 123 def 2 456 abc 1 123 abc 1 123 abc 2 ... I'd like to write a query that outputs: key count category1count category2count 123-abc 3 2 1 123-def 2 1 1 456-abc 1 1 0 So far I've got this: SELECT concat( concat(id1,'-'), id2), count(*) , count( SELECT * WHERE buyingcategory = 1 ??? ) , count( SELECT * WHERE buyingcategory = 2 ??? ) FROM table GROUP

Sum,Case,Union,Group by : Php Mysql

谁都会走 提交于 2019-12-12 04:33:47
问题 SUM CASE not showing proper details Sample date : below is data with group by prdid wghvalue prdid addby cutequl 0.4 57546 me 1 0.6 71256 me 1 0.2 68754 me 1 below is data when i remove group by prdid wghvalue prdid addby cutequl 0.1 57546 me 1 0.1 57546 me 1 0.2 57546 me 1 0.1 71256 me 1 0.5 71256 me 1 0.2 68754 me 1 one strange thing : in above sample data prdb.order cutid.order 2 2 3 2 4 4 so if i am writing query prdb.order - cutid.order as newval i am getting value like ... 2-2 = 0 , 3-2

MySQL - edge case use of GROUP BY

自古美人都是妖i 提交于 2019-12-12 04:24:54
问题 My understanding of GROUP BY is that its standard use is to aggregate items. So a typical example might be: select count(id), department, from table group by department The above would a count of all id's per department. So, I got taught a very useful (but possible pretty dodgy!) trick using group by. I was wondering if this usage has any problems. Although the query runs as expected [results as expected in all cases], my spidey sense is tingling a bit... Imagine the following data set: id |

MySql Query Grouping by Time

拟墨画扇 提交于 2019-12-12 04:15:28
问题 I am trying to create a report to understand the time-of-day that orders are being placed, so I need to sum and group them by time. For example, I would like a sum of all orders placed between 1 and 1:59, then the next row listing the sum of all orders between 2:00 and 2:59, etc. The field is a datetime variable, but for the life me I haven't been able to find the right query to do this. Any suggestions sending me down the right path would be greatly appreciated. Thanks 回答1: If by luck it is

Pandas groupby sum

落花浮王杯 提交于 2019-12-12 04:12:33
问题 I have a dataframe as follows: ref, type, amount 001, foo, 10 001, foo, 5 001, bar, 50 001, bar, 5 001, test, 100 001, test, 90 002, foo, 20 002, foo, 35 002, bar, 75 002, bar, 80 002, test, 150 002, test, 110 This is what I'm trying to get: ref, type, amount, foo, bar, test 001, foo, 10, 15, 55, 190 001, foo, 5, 15, 55, 190 001, bar, 50, 15, 55, 190 001, bar, 5, 15, 55, 190 001, test, 100, 15, 55, 190 001, test, 90, 15, 55, 190 002, foo, 20, 55, 155, 260 002, foo, 35, 55, 155, 260 002, bar,

Using groupy and subplots with pandas dataframe

走远了吗. 提交于 2019-12-12 04:11:18
问题 I have a dataframe object with time series data in multiple columns (see below). I am trying to make a graphic with subplots for each of the columns in the dataframe where each subplot has 12 boxplots, one for each month. I have used the following code to just make subplots from a dataframe before (but for bar not boxplots), labels = df.columns.values fig, axes = plt.subplots(nrows = 3, ncols = 4, gridspec_kw = dict(hspace=0.3),figsize=(12,9), sharex = True, sharey=True) targets = zip(labels,

C# How do I Order By my Transform/Pivot in Ms Access?

喜你入骨 提交于 2019-12-12 04:08:19
问题 Using this code: TRANSFORM SUM(Amount) SELECT DISTINCT IS_Accounts FROM [TABLE] GROUP BY IS_Accounts PIVOT Status I am capable of creating a mini-report summary for my purposes, generated from a much larger database with only the important stuff. This is how it looks like: However the Accounts column is all out of order, some of these need to be above the others in priority. To do this, I've written a query and tested it on the main database. " ORDER BY IIf([IS_Accounts] = 'Revenues' , 1 ,

LINQ query Joins

旧巷老猫 提交于 2019-12-12 04:04:04
问题 When i use the below code to retrieve information, it shows an error.. var mails = from m in entity.mailboxes join p in entity.ordinary_user_profile_info on m.from_id equals p.user_id select new MailList { mid = m.m_id, mfrom = m.**from_id,** // Error occours here mfomname = p.username, msubject = m.subject }; Error is: "int? mailbox.from_id " Cannot implicitly convert type 'int?' to 'int'. An explicit conversion exists (are you missing a cast?) I have declared m_id and from_id as int in DB

How to “group by” in strict string comparation when sql_mode=only_full_group_by is setted in MySql?

ε祈祈猫儿з 提交于 2019-12-12 03:54:35
问题 I want to group by t0.method in strict string comparation, i.e. "GET ", "GET" and "get" in different group, so a BINARY is added in front of the t0.method field which appears in the group by sentence. but I can't add a BINARY to this field which appears in the select sentence, since this will cause an encoding problem when non-ascii characters appears in the data . So following is the SQL query I finally get: SELECT `t0`.`method` AS `d0`, SUM(`t0`.`success`) AS `m0` FROM `invoke_statistics`

group by in Matlab to find the value that resulted minimum similar to SQL

感情迁移 提交于 2019-12-12 03:54:03
问题 I have a dataset having columns a, b, c and d I want to group the dataset by a,b and find c such that d is minimum for each group I can do "group by" using 'grpstats" as : grpstats(M,[M(:,1) M(:,2) ],{'min'}); I don't know how to find the value of M(:,3) that resulted the min in d In SQL I suppose we use nested queries for that and use the primary keys. How can I solve it in Matlab? Here is an example: >> M =[4,1,7,0.3; 2,1,8,0.4; 2,1,9,0.2; 4,2,1,0.2; 2,2,2,0.6; 4,2,3,0.1; 4,3,5,0.8; 5,3,6,0