rank

SQL - how to get unique values in a column (distinct does not help here)

元气小坏坏 提交于 2019-12-13 03:55:52
问题 I have a production case where we track devices that move around warehouses. I have a table that shows these previous locations like this: +--------+------------+-----------+------+ | device | current_WH | date | rank | +--------+------------+-----------+------+ | 1 | AB | 3/15/2018 | 7 | | 1 | CC | 3/19/2018 | 6 | | 1 | CC | 3/22/2018 | 5 | | 1 | CC | 3/22/2018 | 5 | | 1 | DD | 4/23/2018 | 4 | | 1 | DD | 5/11/2018 | 3 | | 1 | DD | 5/15/2018 | 2 | | 1 | DD | 5/15/2018 | 2 | | 1 | AA | 6/6

Ms Access Rank and match two querys

心不动则不痛 提交于 2019-12-13 03:34:51
问题 I've been stuck with this problems for a while, and couldn't get it right yet. Here it is: I have some tables in my Acces database and some querys. I have a query to select some fields and order by, say, their frequency. This is done for two tables, giving me two ranks. Looks like this (and are sorted DESC, so the higher Frequency is on top): Table 1 Table 2 Value1 Frequency1 Value2 Frequency2 Table2.Value2 is a subset of Table1.Value1, so I want to match Value2 and Value1 plus Add a Column

Print Rank from sum in PHP & MySql

这一生的挚爱 提交于 2019-12-13 03:16:24
问题 I have My Sql Database Table as below idno Name Subject Score 1 Mahesh English 55 1 Mahesh Maths 25 1 Mahesh Science 35 2 Richards English 65 2 2 3 3 3 .................. Like ways so on till id number 12000 Now i will provide a form for the user and tell them to enter id number and submit then the output should be. If User Enters idno : 3 and submit the form then the output should be IDNO NAME TOTAL SCORE RANK 1 MAHESH 95 2546 (Example) and here i am using this code $id = mysql_real_escape

R: calculate rank sum automatically

感情迁移 提交于 2019-12-12 16:26:48
问题 Given x <- cbind(c(10,15,20,20,25,30,30,30,35,40,40,40,40,45),rep(c('M','F'),7)) , I want to calculate the rank sums of of categories M and F automatically , without doing it by hand. The thing I couldn't figure out is how to adjust the rank numbers when there is a tie. In this case, #3 and #4 are both 20 and thus share the rank value of 3.5 (instead of 3 and 4). Likewise #6 ~ #8 have the rank value of 7, and #10 ~ #13 have 11.5. Without this adjustment, the sums would be wrong. #Wrong sum

How to include only rows where the following row is within 12 hours and rank accordingly

穿精又带淫゛_ 提交于 2019-12-12 15:22:59
问题 We are trying to include in our SQL only those rows where the next row is within 12 hours, based on a timestamp. Along with this, we also need to rank the rows in order to identify initial contact followed by the number of contacts within the time frame. Unfortunately we cannot just look for min() max() within 12 hours as the date range can be longer (months) but the time between contacts can only be 12 hours. A person may have multiple contacts within the over all date range, and the initial

Get rank of matrix entries?

杀马特。学长 韩版系。学妹 提交于 2019-12-12 14:47:38
问题 Assume a matrix: > a <- matrix(c(100, 90, 80, 20), 2, 2) > a [,1] [,2] [1,] 100 80 [2,] 90 20 Suppose I want to convert the elements of the matrix to ranks: >rank.a <- rank(a) > rank.a [1] 4 3 2 1 This returns a vector, i.e. the matrix structure is lost. Is it possible to rank a matrix such that the output will be of the form: [,1] [,2] [1,] 4 2 [2,] 3 1 回答1: An alternative to @EDi's Answer is to copy a and then assign the output of rank(a) directly into the elements of the copy of a : > a <-

Subgraph layout in graphviz

喜欢而已 提交于 2019-12-12 08:03:08
问题 I have code to display two subgraphs: graph { rankdir=LR; subgraph cluster01 { label="t=0" a0 [label="A"]; a1 [label="B"]; a2 [label="C"]; a5 [label="E"]; a0 -- a1; a1 -- a2 ; a2 -- a0; }; subgraph cluster02 { label="t=10" b0 [label="A"]; b5 [label="E"]; b1 [label="B"]; b2 [label="C"]; b0 -- b1; b2 -- b5; }; a0--b0 [style=dotted]; a1--b1 [style=dotted]; a2--b2 [style=dotted]; a5--b5 [style=dotted]; } This code displays two subgraphs like this: But I want to have it like this: I hope someone

SQL RANK() over PARTITION on joined tables

我只是一个虾纸丫 提交于 2019-12-12 08:00:21
问题 I have two tables RSLTS and CONTACTS: RSLTS QRY_ID | RES_ID | SCORE ----------------------------- A | 1 | 15 A | 2 | 32 A | 3 | 29 C | 7 | 61 C | 9 | 30 CONTACTS C_ID | QRY_ID | RES_ID ---------------------------- 1 | A | 2 2 | A | 1 3 | C | 9 I'm trying to create a report that would show, for each CONTACT record ( C_ID ), the RANK() of RES_ID (by SCORE ) in the RSLTS table within its group ( QRY_ID ). Using the data above, it would look like this: C_ID | QRY_ID | RES_ID | SCORE | Rank ------

SQL Rank based on date

谁说胖子不能爱 提交于 2019-12-12 05:14:52
问题 I am trying to link a customer to a "peferred" merchant based on number of visits within the last 18 months, with the tiebreaker being the most recent visit date. I'm having a bit of trouble with the tiebreaker. If there are two records both ranked 1 based on # of visits for a certain MemberID, I want to set the IsFirst bit column to 1 on the record with the MAX(EncounterDate) for that MemberID. How should I go about doing this? 回答1: This may help you... This is Oracle query based on existing

SQL ranking multiple groups

梦想的初衷 提交于 2019-12-12 03:38:01
问题 For a project I was asked to design a DB for a small Olympic games. This is the ER diagram I made for the DB. For one of the required queries, I need to list the sport, event, name, country, and result(medal) for everyone. So far the only problem I am having is ranking(assigning GOLD, SILVER, or BRONZE) each of the results based only on others in the same event. My query so far: SELECT cy.countryname COUNTRY, c.firstname || ' ' || c.lastname "COMPETITOR", s.sportname, e.eventname EVENT, rs