group-by

MySQL getting SUM of balance grouped by user's job location

爷,独闯天下 提交于 2019-12-13 07:38:15
问题 Im trying to get the SUM of all user balances in a specific month, and grouped by the user's region, which depends on the Point of Sell they work at. balance id_balance date id_user value ($$$) user id_user id_pos name ( not relevant ) pos (Point of Sell) id_pos id_region name ( not relevant ) location_region id_region name (Florida, Texas, etc) Basically, I would need it to present this data (filtered by month): location_region.name | SUM(balance.value) ---------------------|----------------

Mysql scenario - Get all tasks even if there is no entry?

六眼飞鱼酱① 提交于 2019-12-13 07:28:04
问题 I have three tables Tasks with columns Taskid, Taskname TaskAllocations with columns Taskid, EmpNum TaskEntries with columns TaskId, EmpNum, WorkedDate, Hoursspent Now I want to get all the task entries along a particular week. Here my problem is even if there is no Taskentry for a particular task I should get atleast a row with that TaskId, and Taskname with Hoursspent as Null in the query's resultset. I have been trying to get this with the below query. SELECT A.TaskId, B.TaskName, SUM( C

Capping values after a trigger level in a different variable _after GroupBy

不想你离开。 提交于 2019-12-13 07:21:15
问题 There was an elegant answer to a question almost like this provided by EdChum. The difference between that question and this is that now the capping needs to be applied to data that had had "GroupBy" performed. Original Data: Symbol DTE Spot Strike Vol AAPL 30.00 100.00 80.00 14.58 AAPL 30.00 100.00 85.00 16.20 AAPL 30.00 100.00 90.00 18.00 AAPL 30.00 100.00 95.00 20.00 AAPL 30.00 100.00 100.00 22.00 AAPL 30.00 100.00 105.00 25.30 AAPL 30.00 100.00 110.00 29.10 AAPL 30.00 100.00 115.00 33.46

SQL total quanity purchased by year

强颜欢笑 提交于 2019-12-13 06:26:42
问题 My last post was closed. On the AdventureWorks2012 database, I have to write a query using the Purchasing.PurchaseOrderDetail table and list the total quanity purchased for each product during 2006 and label sum as TotatQtyPurchased. I also have to group by ProductID. Here is my lastest query SELECT POD.ProductID, POD.ModifiedDate, SUM(OrderQty) AS TotalQtyPurchased FROM Purchasing.PurchaseOrderDetail POD GROUP BY POD.ProductID HAVING ModifiedDate = '2006' But I get this error. Column

TSQL : the top records of a given partition (conditional)

余生长醉 提交于 2019-12-13 05:55:07
问题 I need to get all the records in TABLE_A where at least the 2 last Status are vacant (relative to Inspection_Date ) and the Room_ID does not exist in TABLE_B . This is a simplified table I am using as an example: TABLE_A : Room_Id Status Inspection_Date ------------------------------------- 1 vacant 5/15/2015 2 occupied 5/21/2015 2 vacant 1/19/2016 1 occupied 12/16/2015 4 vacant 3/25/2016 3 vacant 8/27/2015 1 vacant 4/17/2016 3 vacant 12/12/2015 3 vacant 3/22/2016 4 occupied 2/2/2015 4 vacant

How to renumber rows by groups

岁酱吖の 提交于 2019-12-13 05:46:53
问题 I need to renumber rows by group ( Class, Color, Type ) sequences in column SeqNo from: Class | Color | Type | SeqNo Animal | Brown | Terr | 1 Animal | Brown | Aqua | 3 Animal | White | Terr | 3 Plant | Green | Aqua | 2 Plant | Green | Aqua | 2 Plant | Green | Aqua | 2 Platn | Green | Terr | 9 to: Class | Color | Type | SeqNo Animal | Brown | Terr | 1 Animal | Brown | Aqua | 2 Animal | White | Terr | 1 Plant | Green | Aqua | 1 Plant | Green | Aqua | 1 Plant | Green | Aqua | 1 Plant | Green |

SQL Group By Having Where Statements

社会主义新天地 提交于 2019-12-13 04:57:19
问题 I have a MS Access table tracking quantities of products at end month as below. I need to generate the latest quantity for a specified ProductId at a specified date e.g. The Quantity for ProductId 1 on 15-Feb-12 is 100 , The Quantity for ProductId 1 on 15-Mar-12 is 150 . ProductId | ReportingDate | Quantity| 1 | 31-Jan-12 | 100 | 2 | 31-Jan-12 | 200 | 1 | 28-Feb-12 | 150 | 2 | 28-Feb-12 | 250 | 1 | 31-Mar-12 | 180 | 2 | 31-Mar-12 | 280 | My SQL statement below bring all previous values

Group by and get the last row

一曲冷凌霜 提交于 2019-12-13 04:47:37
问题 When I used the SELECT * FROM reports WHERE staff='$username' GROUP BY taskid on my query, I get a result of the first row from that group. What do I need to add to get the result from the last row of that group? last row means having id greater than the other row from that group. I tried adding ORDER BY id DESC or ORDER BY id but it did not return the intended result. 回答1: You are using a group by function without any aggregate functions. You probably want to do an order by instead (No group

Minimum distance and group by

折月煮酒 提交于 2019-12-13 04:45:13
问题 I'm trying to make a query which give the nearest shop from a city. I've this table (The result of a query in fac recorded in temporary table) id_Customer | id_Shop | distance ------------------------------- 1 | 1 | 10 1 | 2 | 30 1 | 3 | 100 2 | 3 | 150 2 | 2 | 300 2 | 1 | 400 I would have this result (The minimal distance) id_Customer | id_Shop | distance ------------------------------- 1 | 1 | 10 2 | 3 | 150 How can I do this? 回答1: Here is an excellent article in the official MySQL

pandas groupby ignoring NAs

余生长醉 提交于 2019-12-13 04:37:09
问题 I have a DataFrame which has a lot of NAs. pandas's groupby operation is ignoring any combinations with NA in it. Is there a way to include NAs in groups? If not, what are the alternatives to pandas groupby? I really don't want to fill in NAs because the fact that something is missing is useful information. Edit: I noticed that my question is exactly the same issue reported in groupby columns with NaN (missing) values Has there been any developments technology to get around this issue? 回答1: I