group-by

How to show all names for identical contract in T-SQL

霸气de小男生 提交于 2019-12-25 00:51:04
问题 I have query like this, and i shows me sort of good results select vup.UgovorId, count(P.Naziv) as BROJNAZIVA from [TEST_Ugovori_Prod].dbo.VezaUgovorPartner as vup inner join [TEST_MaticniPodaci2].[dbo].[Partner] as p on vup.PartnerId = p.PartnerID group by vup.UgovorId Results are like this (first row is vup.UgovorId, second is p.Naziv): 1264 1 1265 3 But I want to show all p.Naziv when that row has more then one for that vup.UgovorId like string so I would be like this: 1264 "Mark" 1265

Replace column values within a groupby and condition

瘦欲@ 提交于 2019-12-25 00:46:22
问题 I have a dataframe that I want to find the minimum value of a column within a group, and then based on that row, update the values of some of the other columns. The following code does what I want: import pandas as pd df = pd.DataFrame({'ID': [1,1,1,2,2,2,], 'Albedo': [0.2, 0.4, 0.5, 0.3, 0.5, 0.1], 'Temp' : [20, 30, 15, 40, 10, 5], 'Precip': [200, 100, 150, 60, 110, 45], 'Year': [1950, 2000, 2004, 1999, 1976, 1916]}) #cols to replace values for cols = ['Temp', 'Precip', 'Year'] final = pd

Rails 5.1 group_by year and month and show both

隐身守侯 提交于 2019-12-25 00:33:36
问题 I'm working on a rails app for my expenses. I have 3 models like : user, spending and currency. I can create a spending via form, I have a title, description, amount, currency_id, user_id. All the relations are made and working. I use my show.html.erb from the user controller to display all the expenses from the current_user. That works fine. I then I grouped the expenses together and sort them by date. I did actually 2 groups, the first one which is today and the rest. So on the display it

C# Linq UNION syntax on 2 complex queries

自闭症网瘾萝莉.ら 提交于 2019-12-25 00:10:25
问题 This is pretty complicated for a person just learning Linq! I asked how to JOIN and GROUP BY in this question and a BIG SHOUT OUT to TriV for his explicit and very helpful answer. Now, I want to take my already very complicated query and create a UNION to a similar query. I have below, 2 separate SQL queries that I have put into 1 query using a UNION clause. The first query joins two tables. But the second query is against only one table, because it is for unassigned assets that are not

Group by quarter (datepart) returns multiple rows with same quarter

不羁岁月 提交于 2019-12-25 00:09:25
问题 I'm trying to return a count for the total number of records in the table HISTORY grouped by their quarter and year. Currently I have: SELECT DISTINCT (CAST(DATEPART(year, CREATE_DATE) AS char) + ' Qtr' + CAST(DATEPART(quarter, CREATE_DATE) AS char)) AS Period, COUNT(ID) FROM HISTORY GROUP BY CREATE_DATE ORDER BY Period; But I'm getting duplicate rows with the same quarter and year. I'm also getting a total of records counted that's lower than the total records in the table. Here's a sample

MySQL query to get last 12 months data grouped by month including zero counts

折月煮酒 提交于 2019-12-24 21:27:31
问题 I have table orders (order_id, order_processed_date) . I want the count of orders per month for last 12 months. If any month has 0 orders, then it should print 0. Something like this: Total Orders | Month ----------------------- 2 | OCT 2018 3 | SEP 2018 0 | AUG 2018 0 | JUL 2018 1 | JUN 2018 0 | MAY 2018 0 | APR 2018 0 | MAR 2018 5 | FEB 2018 5 | JAN 2018 0 | DEC 2017 0 | NOV 2017 I already searched in this website and get some queries but did not find exact solution for this. I get result

Reindex pandas dataframe based on uneven dates and then groupby and blank fill certain values

柔情痞子 提交于 2019-12-24 20:47:45
问题 I have a dataframe that looks something like this: df Name date season binary Apple 2016-04-24 MAM 1 Banana 2016-05-01 MAM 1 Berry 2016-05-01 MAM 1 Berry 2017-11-05 OND 1 Orange 2016-11-27 OND 1 Kiwi 2017-03-27 MAM 1 And I have a long date time object of a bunch of dates like this: df1 date season Week 2016-03-28 MAM 13 2016-04-04 MAM 14 2016-04-11 MAM 15 2016-04-18 MAM 16 2016-04-25 MAM 17 2016-05-02 MAM 18 2016-05-09 MAM 19 2016-05-16 MAM 20 2016-05-23 MAM 21 2016-05-30 MAM 22 2016-06-06

How do I sum only the 3 best scores from this query?

坚强是说给别人听的谎言 提交于 2019-12-24 20:43:57
问题 I need to sum only the 5 best scores for each player from 11 events. The query below creates a leaderboard which sums all the scores but I'm stuck as to how i can only sum the 5 best scores. I've abbreviated the query to show only 4 events and getting best 3 results to shorten the post, but hope it gets across, what I need. SELECT playerID AS Player, SUM(CASE WHEN championshipleaderboard.eventID = 1 THEN championshipleaderboard.points ELSE 0 END) AS Event1, SUM(CASE WHEN

SQL Server : group by consecutive

眉间皱痕 提交于 2019-12-24 20:42:02
问题 I have this table: CREATE TABLE yourtable ( HevEvenementID INT, HjvNumeSequJour INT, HteTypeEvenID INT ); INSERT INTO yourtable VALUES (12074, 1, 66), (12074, 2, 66), (12074, 3, 5), (12074, 4, 7), (12074, 5, 17), (12074, 6, 17), (12074, 7, 17), (12074, 8, 17), (12074, 9, 17), (12074, 10, 5) I need to group by consecutive HteTypeEvenID . Right now I am doing this: SELECT HevEvenementID, MAX(HjvNumeSequJour) AS HjvNumeSequJour, HteTypeEvenID FROM (SELECT HevEvenementID, HjvNumeSequJour,

SQL query to get min, max rows

人走茶凉 提交于 2019-12-24 19:44:24
问题 I have following sample data, I want to get min and max time of every consecutive status. cat subcat status logtime fruits apple 0 30-10-2017 06:00 fruits apple 0 30-10-2017 06:03 fruits apple 0 30-10-2017 06:06 fruits apple 0 30-10-2017 06:09 fruits apple 0 30-10-2017 06:12 fruits apple 0 30-10-2017 06:15 fruits apple 0 30-10-2017 06:18 fruits apple 0 30-10-2017 06:21 fruits apple 0 30-10-2017 06:24 fruits apple 0 30-10-2017 06:27 fruits apple 0 30-10-2017 06:30 fruits apple 0 30-10-2017 06