I have the following data:  account_id note_id size     id ---------- ------- ------ -------- 48         1554    196036 28229509 48         1554    18777  28229588 48         1554    4861   28229566 48         1559    176406 28229516 48         1559    82041  28229521 48         1559    3063   28229541 48         1583    92150  28229514 48         1583    3495   28229501 48         1583    119203 28229534 8764       25556838 5126   28229567 8764       25556838 340618 28229508   I want to get the id of the highest value on the size column, for each note_id.  Example:  note_id: 25556838 size: 340618 id: 28229508  note_id: 1583 size: 119203 id: 28229534   How can I get that data?
I have a query pattern that must be very common, but I don't know how to write an efficient query for it.  I want to look up the rows of a table that correspond to "the most recent date not after" the rows of another table.  I have a table, inventory say, which represents the inventory I hold on a certain day.  date       | good | quantity ------------------------------ 2013-08-09 | egg  | 5 2013-08-09 | pear | 7 2013-08-02 | egg  | 1 2013-08-02 | pear | 2   and a table, "price" say, which holds the price of a good on a given day  date       | good | price -------------------------- 2013-08-07 | egg  | 120 2013-08-06 | pear | 200 2013-08-01 | egg  | 110 2013-07-30 | pear | 220   How can I efficiently get the "most recent" price for each row of the inventory table, i.e.  date       | pricing date | good | quantity | price ---------------------------------------------------- 2013-08-09 | 2013-08-07   | egg  | 5        | 120 2013-08-09 | 2013-08-06   | pear | 7        | 200 2013-08-02 | 2013-08-01   | egg  | 1        | 110 2013-08-02 | 2013-07-30   | pear | 2        | 220   I know one way of doing this:  select inventory.date, max(price.date) as pricing_date, good from inventory, price where inventory.date &gt;= price.date and inventory.good = price.good group by inventory.date, good   and then join this query again to inventory. For large tables even doing the first query (without joining again to inventory) is very slow.  However, the same problem is quickly solved if I simply use my programming language to issue one max(price.date) ... where price.date &lt;= date_of_interest ... order by price.date desc limit 1 query for each date_of_interest from the inventory table, so I know there is no computational impediment.  I would, however, prefer to solve the whole problem with a single SQL query, because it would allow me to do further SQL processing on the result of the query.  Is there a standard way to do this efficiently? It feels like it must come up often and that there should be a way to write a fast query for it.  I'm using Postgres, but an SQL-generic answer would be appreciated.
Replace Line Breaks in a String C# How can I replace Line Breaks within a string in C#? What is the difference between a telephoto lens and a zoom lens? Looking at the , I notice a distinction between telephoto lens and zoom lens.  What is the difference between the two?  Why would I want one over the other?  I  but remain confused about this distinction.  Please talk to me like I'm stupid. :) I am hoping for a completely lay explanation.  In particular, I'd like to understand in what situations I'd use a telephoto lens, and in what (other) situations I'd use a zoom lens. "Compared with" vs "Compared to"—which is used when? Is only one of them correct? Are they used in different situations? Or are they interchangeable? Process management and high technology weapon. Novel name and author? I am looking for help to point me out at a very old novel (likely from the '60s) about two empires at interstellar war. When it comes to starships, one is technologically very advanced, and the other has very low and inefficient technology.  The highly advanced empire has apparently strong chances to win the war, in particular considering a new technology they were developing. I remember the technology to work like this: consider the space as a flat surface, and on this surface, a disk around the spaceship. When the technology was turned on, this disk was stretched out, as made of rubber, so that it produced a cone, with the tip being the spaceship. The spaceship was therefore teleported 10 parsec away (if I remember correctly), but retained all the connections to the original position. If the spaceship moved, the cone moved as well. This allowed to move in position among enemy ships completely unnoticed, by stretching while afar, then moving in the proper position 10 parsecs away, then destretching.  Despite this technology, the empire lost the war because of delays. It's a perfect example of how having a disruptive technology does not guarantee to win against the competitors.  I am trying to find out the author and name of this novel, hopefully with the date of publication and in which journal/magazine. I wish to show that $\mathbb{Q}(\sqrt2, \sqrt3)$ is not isomorphic to $\mathbb{Q}(\sqrt[4]2)$.    What I did so far was to show that $\mathbb{Q}(\sqrt2,\sqrt3) =\text{span}\{1,\sqrt2,\sqrt3,\sqrt6\}$.  Assuming they are isomorphic, denoting $f$ the isomorphism, then $f(1) = 1$, so $x^2-3$ has a root in $\mathbb{Q}(\sqrt2,\sqrt3)$ so $\sqrt 3\in\mathbb{Q}(\sqrt[4]2)$. ($\sqrt2 \in \mathbb{Q}(\sqrt[4]2)$, $\sqrt[4]2\cdot\sqrt[4]2=\sqrt2)$.   Thus under the assumption, $\mathbb{Q}(\sqrt2, \sqrt3)\subseteq \mathbb{Q}(\sqrt[4]2)$. As a vector spaces of the same dimension over $\mathbb{Q}$, it means that $\mathbb{Q}(\sqrt2, \sqrt3)= \mathbb{Q}(\sqrt[4]2)$.  Now all is left to do it to show a contradiction: $\sqrt[4]2\in\mathbb{Q}(\sqrt2,\sqrt3)$, then $\sqrt[4]2 = a+b\sqrt2+c\sqrt3+d\sqrt6$ so $2=(a+b\sqrt2+c\sqrt3+d\sqrt6)^4$, I believe that opening the expression, I would find out that it can't be an element of $\mathbb{Z}$. However this is a really inelegant way (if it really works), and I wish for a better way to do so.  An other approach: $\mathbb{Q}(\sqrt2,\sqrt3) = \mathbb{Q}(\sqrt2 + \sqrt3)$ by the irreducibility of $x^4-10x^2+1$ over $\mathbb{Q}$ (an some dimension theorem usage). Also, $x^4-10x^2+1$ splits in $\mathbb{Q(\sqrt2, \sqrt3)}$.   Is there a way to show that this polynomial doesn't split over $\mathbb{Q}(\sqrt[2]4)$? with different method then assuming that $\sqrt3\in\mathbb{Q}(\sqrt[4]2)$ and getting a contradiction? Maybe the fact that $\sqrt[4]2$ has complex roots might help? I would like to create a table with some columns' width specified, while the text in those columns should be centered both horizontally and vertically. I found out that  \usepackage{array} \begin{tabular}{| c | c | m{5cm} |}   vertically centers the text in the last column, but justifies it horizontally (like text in normal paragraphs).  Update: With Jake's method, it seems both \\ and \hline cause an error. How to fix it? The given differential equation $$\lvert{dy\over{dx}}\rvert\,+\mid{y}\mid+1=0 $$  I don't know how to deal with modulus sign in order to prove the statement  Reference-Different Equations by Shipley L Ross Ch1 Exercise 7(a) How to spawn a Giant with equipment? I really want to spawn Giant with armor and swords. Because Giants are strong, and great challenge if spawned with enchanted diamond armor and a diamond sword. How do you pass a function as a parameter in C? I want to create a function that performs a function passed by parameter on a set of data. How do you pass a function as a parameter in C? Can a finite sum of square roots be an integer? Can a sum of a finite number of square roots of integers be an integer? If yes can a sum of two square roots of integers be an integer?  The square roots need to be irrational. Making separate Python installation that can call ArcPy? I see a lot of Q&amp;As asking how you can create a separate Python installation (e.g. the Anaconda or Python XY distribution) that can use arcpy, while not 'breaking' the original ArcGIS python installation.  I had this same problem, and I think I have found a 'universal' solution. So far we have done this on about 8 computers at work and it all works fine.   How to install a separate Python distribution that can use ArcGIS? Problem with package lineno I'm using package lineno for proofreading of my documents.  So I usually have something like the following MWE:  \documentclass{article}  \usepackage{blindtext}  \usepackage{ifthen}           % to use if then else \newboolean{korrektur}        % for proofreading: true/false  \setboolean{korrektur}{true} % choose one, comment the other %\setboolean{korrektur}{false}  % What we need for proofreading \ifthenelse{\boolean{korrektur}}% proofreading wanted? {% YES:   \usepackage{showframe}          % shows type area   \usepackage{lineno}             % numbers lines   \pagewiselinenumbers            % lines per page }% {% NO: % error if lineno was used before:   \typeout{***** Please delete .aux files if you get errors! *****} % What to add here so that I get no errors?  %&lt;================= }  \begin{document} \Blindtext \end{document}   Run it two times. Everything should be well, blindtext is numbered.  Now please move the % sign from line 8 (false) to line 7 (true).    Because we had had the run before there is an .aux-file, including lines with the macro \@LN.  If you compile now you will get the following error message (and some more):   ***** Please delete .aux files if you get errors! ***** (C:\Users\...\LaTeX\_TeX.SX\lineno\test-lineno.aux ! Undefined control sequence. l.2 \@LN         {0}{0}   Question:  Is it possible to add in line 20 (see %&lt;===========) something to get rid of the error messages? Something that resets the meaning of macro \@LN? I am trying to run the following model:         I(week^2):mutation_status +         (week + I(week^2) | subject_id) ,          data = sim_dat)  This is the output I get from this model. The correlation between week and I(week)^2 is rather high (-0.95) and I was curious to know how I can change my data simulation code to lower that value. I am also having issues with convergence and would love to get thoughts on how to avoid issues regarding convergence. Thank you! Linear mixed model fit by REML. t-tests use Satterthwaite's method [lmerModLmerTest]  Formula: fetal_weight ~ week + mutation_status + week:mutation_status + I(week^2) +  I(week^2):mutation_status + (week + I(week^2) | subject_id) Data: sim_dat  REML criterion at convergence: 114  Scaled residuals:      Min      1Q  Median      3Q     Max  -1.9343 -0.3980 -0.0075  0.4168  1.9928   Random effects:  Groups     Name        Variance  Std.Dev. Corr         subject_id (Intercept)   1.51524  1.2309                          week         61.01832  7.8114   0.16                   I(week^2)   496.20236 22.2756  -0.19 -0.95  Residual                 0.05892  0.2427              Number of obs: 100, groups:  subject_id, 20  Fixed effects:                            Estimate Std. Error       df t value       Pr(&gt;|t|)     (Intercept)                  3.1331     0.4226  17.9961   7.413 0.000000713699 *** week                        -1.2465     3.5210  18.0053  -0.354          0.727     mutation_statusY             0.5061     0.5977  17.9961   0.847          0.408     I(week^2)                   34.5706    10.8146  18.0084   3.197          0.005 **  week:mutation_statusY       -1.0697     4.9795  18.0053  -0.215          0.832     mutation_statusY:I(week^2) 202.5521    15.2942  18.0084  13.244 0.000000000101 *** --- Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1  Correlation of Fixed Effects:             (Intr) week   mttn_Y I(w^2) wk:m_Y week        -0.160                             muttn_sttsY -0.707  0.113                      I(week^2)    0.145 -0.966 -0.103               wk:mttn_stY  0.113 -0.707 -0.160  0.683        mtt_Y:I(^2) -0.103  0.683  0.145 -0.707 -0.966  Code for data simulation: set.seed(123)  # set the seed J &lt;- 20  # number of individuals (clusters) cs &lt;- 5  # number of time points (cluster size) gam &lt;- c(0, 0.75, 1.34)  # fixed effects G &lt;- matrix(c(1.75, 0, 0,               0, 0.0125, 0,               0,0,0.0625),              nrow = 3)  # random effect variances (G-matrix) sigma2 &lt;- 0.08  mutation_status &lt;- rep(0:1, each = 5) mutation_status &lt;- rep(mutation_status, times = 10)  X &lt;- cbind(1, seq_len(cs),             (seq_len(cs))^2)  # for each individual X &lt;- X[rep(seq_len(cs), J), ]  X &lt;- X[rep(seq_len(cs), J), ]  X[,2] &lt;- X[,2]*0.05 X[,3] &lt;- X[,3]*0.05  # repeat each row cs times pid &lt;- seq_len(J)  # individual id pid &lt;- rep(pid, each = cs)   # Generate person-level (lv-2) random effects uj &lt;- lmf::rmnorm(J, mean = rep(0, 2), varcov = G)  # Generate repeated-measure-level (lv-1) error term eij &lt;- rnorm(J * cs, sd = sqrt(sigma2))  # Compute beta_j's betaj &lt;- matrix(gam, nrow = J, ncol = 3, byrow = TRUE) + uj  # Compute outcome: y &lt;- rowSums(X * betaj[pid, ]) + eij + mutation_status*X[ , 3]*10 + 3  # Form a data frame sim_dat &lt;- tibble(y, time = X[ , 2], pid, mutation_status) sim_dat &lt;- sim_dat[,c(3,2,4,1)] colnames(sim_dat) &lt;- c(&quot;subject_id&quot;, &quot;week&quot;, &quot;mutation_status&quot;, &quot;fetal_weight&quot;) sim_dat$week_2 &lt;-sim_dat$week*5 + 15  sim_dat$mutation_status &lt;- as.factor(ifelse(sim_dat$mutation_status == 0, &quot;N&quot;, &quot;Y&quot;)) sim_dat$subject_id &lt;- as.factor(sim_dat$subject_id ) #Model Building I would like to clarify something that I don't think is clear in   The first automatic delete rule kicks in at 9 days for closed questions:     If the question was closed more than 9 days ago, and ...         was not closed as a duplicate   has a score of 0 or less   has no answers with a score > 0   some other criteria that don't matter right now...      Then, at 30 days, there's:     If the question is more than 30 days old, and ...         has −1 or lower score   has no answers   is not locked      This rule applies to both open and closed questions, but it doesn't mention the same exemption for duplicates.  I'm pretty sure that I've seen old, downvoted duplicates disappear on ServerFault (and that fits what the rule says), but I'm also sure I've seen lots of comments along the lines of  "duplicates aren't deleted."  So what I'm after is a clear statement from a power-that-be or a clear reference that says "duplicate questions fall under the same 30-day automatic deletion rule as any other question."  (or that they don't)  (Note: I realize this doesn't apply the stub left behind when a question is merged into another.  Those "stubs" are locked and are never deleted.) Drop rates for set / legendary items Just wondering what the drop rates were for Set / Legendary items, or is it totally random? I imagine they would increase for later acts in Inferno. My monk is comfortable in Act 3 in Inferno, but I've only found one set item, so MF will increase chances for them? Don't remember the exact start to the story, but it went something like "walking along a path" or something, and when he hears what sounds like a shotgun blast behind him, he then feels something strike him in the butt. He passes out, and when he awakens, he discovers that the "shotgun blast" was actually a miniature spaceship that exploded and shot miniature aliens into his body. The aliens prove to be very beneficial because they clean up all the toxins and other poisons in his body. They can be transmitted through kissing or sexual activity.  Any help with the name of the story would be greatly appreciated.  Dan How to disable sticky corners in Windows 10 It seems Microsoft has tried to solve this problem .  In Windows 7, there is no boundary between monitors and the mouse can move freely across the top of the screen between my 3 monitors, provided I had set their heights equal in display settings. Windows 8 introduced sticky corners. See .  Windows 10 got sticky corners as well. There are a few pixels at the top corners of each display where the mouse cannot cross over onto the other display. One must move the cursor down to avoid this region in order to get to the next display.  The image shows roughly the region where mouse movement is not permitted in Windows 10, but is allowed in Windows 7.    Personally, I had no problem with unrestricted mouse movement across the top of my screens - I got used to "aiming" for the x, and the convenience of unrestricted cursor movement. Like all the people who wanted to disable it in W8, I'm wondering if there is a way to disable it in W10.  Edit to address possible duplicate:  Although the problem is identical to the one in , solutions to solve the problem in W8 involving editing the registry key MouseCornerClipLength do not work in W10, since that registry key is not present in W10. Also adding that key and setting the value doesn't work. I searched the entire registry and couldn't find it in another location. No other W10 keys in the node referenced in the W8 solution are obvious replacements.  Edit to address possible solutions in comments  harrymc's  and  that worked for for Windows 8.1 do not work in Windows 10. Do we use the SD of whole population or SD of just one sample to calculate SE of samples means in central limit theorem? I'm learning applications on Central Limit Theorem and got really confused with a few points. According to this , the procedure to apply CLT usually goes like this:   So if SD is the population standard deviation, how are we gonna get it?? Isn't the whole population standard deviation what we eventually calculate by applying CLT and analyzing a sample of the whole population? How come the population standard deviation become a prerequisite??   Please tell me this tutorial is wrong.   I think the SD actually refers to the standard deviation of a sample (of some size n), which we can actually get easily. For example:    sample the whole population with a sample size of n (e.g. randomly select 10000 users from the whole population of 10 billions) calculate the mean of the 10000 measurements. calculate SE = SD / sqrt(10000), where SD is the standard deviation of the 10000 measurements, instead of the standard deviation of the whole population of 10 billions.    This explanation would make much more sense.   Any thoughts? Run a program X times I have a WordPress install on a dedicated server with decent memory (upwards of 8GB).  The WordPress install includes many plugins - 50 active plugins. Most important to note is the  plugin to make WordPress multilingual. The theme is .  The stack is LAMP - CentOS 6.3, Apache 2.4.4, Percona MySQL, PHP-FPM.  I have been quite stupid, and didn't set up a test or staging server.  Everything was running fine till I updated to WordPress 3.8, and also updated several plugins at the same time.  I didn't pay attention at the time, but all my widgets got messed up, and so did any sort of navigation etc.  I enabled error_log for a bit, i.e.  ini_set('log_errors',TRUE); ini_set('error_reporting', E_ALL); ini_set('error_log', dirname(__FILE__) . '/error_log.txt');   This resulted in an immense file - basically the error_log grows by about a GB every 4 minutes or so.  The primary error I found in the error log was database server disconnect, better known as      MySQL server has gone away   The first priority was to patch the problem. So I installed  plugin. This mostly, though not completely solved the issue. Many of the widgets came back.  However, the special (non-English) characters are all messed up (converted to question marks). I tried to fix this by opening wp-mysql-ping.php and commenting out   if ( !DB_CHARSET &amp;&amp; version_compare(mysql_get_server_info($this-&gt;dbh), '4.1.0', '&gt;='))                                     {                                         $this-&gt;query("SET NAMES '" . DB_CHARSET . "'");                                     }   Didn't help.  Besides, the plugin is not a permanent or complete solution. So leaving the site in this messed up state, I started working on other possibilities:  As suggested at , I edited my.cnf to add  wait_timeout = 60   Didn't help.  Also added caching to my.cnf  query_cache_type = 1 query_cache_limit = 8M query_cache_size = 512M   Didn't help.  (and yes, I restarted mysql every time I edited my.cnf)  Also tried the method : In wp-db.php before  $this-&gt;select( $this-&gt;dbname, $this-&gt;dbh );   I added  $this-&gt;query("set session wait_timeout=600" );   Didn't help.  I'm at my wit's end. Please help!