I have the following code:  DECLARE @Latest TABLE (     DomainId bigint,      [date] datetime2 )  DECLARE @Rows int DECLARE @History int  INSERT INTO @Latest (DomainId, date) SELECT DomainId, MAX(Date) FROm DomainDetailDataHistory GROUP BY DomainId  SELECT @Rows = COUNT(DomainId) FROM @Latest  SET @History = @Rows * 5  SELECT DISTINCT TOP(@History)    c.DomainId   , c.[Date]   , Passed  FROM DomainDetailDataHistory c JOIN  @Latest h ON h.DomainId = c.DomainId WHERE c.[Date] != h.[Date] ORDER BY c.Date DESC   This code gets me the latest inserted row given by Id and the last 5 insertions.   Problem:   This works all good when I have 5 insertions of every unique DomainId.  I tried adding a new one and since the new one did not have any prior insertions the code gave me the top 7 insertions to compensate for the extra domain.   Clarity:  @History gives me how many different domains I have. I multiply this by 5 to get 5 of each.   Problem is when one of the domains do not have 5 insertions, lets say it only has one then I get more than the top 5 of the other domains.  How do I make sure that I always only get 5 of each and NOT MORE?
I often need to select a number of rows from each group in a result set.  For example, I might want to list the 'n' highest or lowest recent order values per customer.  In more complex cases, the number of rows to list might vary per group (defined by an attribute of the grouping/parent record). This part is definitely optional/for extra credit and not intended to dissuade people from answering.  What are the main options for solving these types of problems in SQL Server 2005 and later? What are the main advantages and disadvantages of each method?  AdventureWorks examples (for clarity, optional)   List the five most recent recent transaction dates and IDs from the TransactionHistory table, for each product that starts with a letter from M to R inclusive. Same again, but with n history lines per product, where n is five times the DaysToManufacture Product attribute. Same, for the special case where exactly one history line per product is required (the single most recent entry by TransactionDate, tie-break on TransactionID.
Let $R$ be a commutative ring with finitely many maximal ideals $\mathfrak m_1,\ldots,\mathfrak m_n$. Let $M$ be a finitely generated module. Then there exists an element $x\in M$ such that $\frac{x}{1}\not\in\mathfrak m_iM_{{\mathfrak m}_i}$ for every $i=1,\dots,n$.    I cannot prove that such an element there exists. I was trying to prove it by induction on $n$. If $n=1$ it is true by Nakayama, so suppose it is true for $n-1$. Then for every $i$ I can find an $x_i\in M$ such that $\frac{x_i}{1}\not\in \mathfrak m_jM_{\mathfrak m_j}$ for every $j\neq i$. If $\frac{x_i}{1}\not\in \mathfrak m_iM_{\mathfrak m_i}$ for some $i$ we are done, so suppose $\frac{x_i}{1}\in\ m_iM_{m_i}$ for every $i$. I don't know how to go on, could you help me? Windows 7 equivalent for ntrights.exe I'm having a problem setting up a vhost on Apache 2.4, using CentOS 6.3.  This question seems to have been answered several times on this forum, but none of the solutions work for me.  Basically, I set up a vhost with a particular document root. When I attempt to access the site, I get a permissions error. But I have no problem if I use a different root.  More specifically, if I set the root to be /volume1/web/xxx, I get a 503 because of a permission problem on index.html.  But if I set it to be /volume1/web, the index.html comes up without a problem.  The details:   I set the persmissions on volume1, web, and xxx to 755. I set the permissions on the index.html files to 777. I copy the index.html file to both /volume1/web and /volume1/web/xxx, so that they have identical index files with identical permissions.   In httpd.conf, I set the VirtualHost options so that I can easily switch the document root by changing 2 comment marks  I have the following lines in the conf file:  NameVirtualHost *:80  &lt;VirtualHost *:80&gt;     ServerName localhost     #DocumentRoot /volume1/web     DocumentRoot /volume1/web/xxx      #&lt;Directory /volume1/web&gt;     &lt;Directory /volume1/web/xxx&gt;       Options Indexes FollowSymLinks Includes ExecCGI       AllowOverride All       Order Allow,Deny       Allow from all     &lt;/Directory&gt;      ErrorLog logs/localhost-error_log     CustomLog logs/localhost-access_log common &lt;/VirtualHost&gt;   These lines contain all the suggestions that worked for other people with the same problem.  What I get when I enter localhost in my browser depends on the document root.   If the root is /volume1/web, the index.html page comes up. if the root is /volume1/web/xxx, then I get a 503 error, and the apache error log has this line:  [Thu Jul 19 17:17:52 2012] [error] [client ::1] (13)Permission denied: access to /index.html denied   I also tried adding an index.php file to the directory. I then got permission denied messages for both the php file and the html file.  I also tried setting the user : group to apache : apache on the directories and files. That didn't help.  I've done everything I can think of to fix the permissions, to no avail.  Does anyone have an idea about what's happening here?  Thanks. Looking at   13.04 will reach EOL in January 2014, while 12.10 will reach EOL in April 2014, therefore if a 12.10 user hasn't upgraded to 13.04 and subsequently to 13.10, there will be a 3 month period where a 12.10 user has a supported version of Ubuntu, but will be unable to upgrade.  I asked this question a number of months ago and the suggestion was that the hope was that there would be an upgrade path from 12.10 to 14.04.  Could somebody confirm whether this is still the case, or if not what the plans are for 12.10 users after 13.04 becomes EOL.  Edited for clarification  The particular issue I was concerned about is that once 13.04 goes EOL, a 12.10 user would in theory lose the ability to upgrade once the 13.04 repo's are removed from the normal release repository.  Using the old releases method would be a way around the issue, however would make it more complicated for a less experienced user.  An alternative could be for the 13.04 repo's to be left available for the 3 month interim period so that a 12.10 version could still be upgraded to 13.04 and subsequently onto 13.10, however that doesn't seem an optimal solution in that users may consider that it meant that support for 13.04 was being continued.  If a direct upgrade from 12.10 to 14.04 was to made available, this would only be available once 14.04 was released and still leaves the issue of the 3 months between January and April 2014 were there may be some confusion.  I suspect that its not going to affect a significant number of users, if somebody has upgraded from 12.04LTS to 12.10, in all probability, they'll have continued to upgrade to 13.04 and upwards because they'd made the choice to use current rather than LTS releases.  It would just be useful to have some clarification of the situation which people can be referred to in advance of 13.04 going EOL rather than hitting the cut off point and it being too late for users to make the decision and being left in limbo. Compiler warning: null reference exception I have the following code in Visual Studio 2005.      Dim OutFile As System.IO.StreamWriter     Try         OutFile = New System.IO.StreamWriter(Filename)        // Do stuff with OutFile     Catch Ex As Exception        // Handle Exception     Finally        If OutFile IsNot Nothing Then OutFile.Close()     End Try   But VS2005 brings up the warning for the line "If OutFile IsNot.." that      Variable 'OutFile' is used before it has been assigned a value. A null reference exception could result at runtime.   Is there some way of removing this warning by subtly altering the code or is there just a better way of doing what I'm trying to do?  Thanks  Rob Creating a gradient-based legend I have a map with graduated symbology, with 328 unique values. I would like to add a legend to my map (as in the picture), illustrating that light blue indicates low values and dark blue high values.  I have done this in ArcGIS before. Is there a way to do this in QGIS as well? how to tell Latex to ignore empty lines I need to externally limit a process/session to a certain number of cores.  Are there any other possibilities than CPU affinity (I don't like the need to specify the actual cores) and cgroups (hard to integrate into our project)? Can Spirit Guardians affect enemies through walls? An element of a group has the same order as its inverse If $a$ is a group element, prove that $a$ and $a^{-1}$ have the same order.   I tried doing this by contradiction.    Assume $|a|\neq|a^{-1}|$  Let $a^n=e$ for some $n\in \mathbb{Z}$ and $(a^{-1})^m=e$ for some $m\in \mathbb{Z}$, and we can assume that $m &lt; n$.  Then $e= e*e = (a^n)((a^{-1})^m) = a^{n-m}$. However, $a^{n-m}=e$ implies that $n$ is not the order of $a$, which is a contradiction and $n=m$.  But I realized this doesn't satisfy the condition if $a$ has infinite order. How do I prove that piece? Chromatic polynomial properties I have some properties which I do not understand how to form a proof for. Most of them are by induction, which is not my strong point Any help would be fantastic.   Looking at the chromatic polynomial $$P_G(k)=P_{G-e}(k) - P_{G/e}(k)$$  Properties   1.If G has n  vertices then $ P_g(k)$ has degree n and the coefficient of $k^n $ is 1   The signs of $P_g(k) $ alternate If G has q components the smalles non-zero term of $P_g(k)$ is the term in $k^q$ Find the infinite sum of the series $\sum_{n=1}^\infty \frac{1}{n^2 +1}$ Design problem - Implement an approval process on case, which sends email to approver showing some additional info, which should not be visible to case owner/agent (who clicked on "Submit for approval" button).  Possible solution - All that additional info will not be stored on Case (otherwise agent will also be able to see it). I am creating a child object to case, where all that additional info be stored. We can make sure agent does not have access to that child object (lets call it ChildObj).   In the email template used, we can include info about that child object. From what i understand, standard email templates dont allow cross object reference. We probably need to use visualforce email templates.  Questions -  1) Can anyone see/point out any issues with that design? 2) I am very new to salesforce. Can anyone give me any example of how i will access child record's field? I mean there won't be any lookup or anything to child object, right? How do i access a field on the child object? Any clue would be helpful KeyboardViewer app is saved from this AppleScript.  on run {input, parameters}     if application "KeyboardViewer" is running then         quit application "KeyboardViewer"     else          activate application "KeyboardViewer"     end if     return input end run   Dock toggle save. Adding shortcut to above, needs some work...   Syntax error Can’t set application "KeyboardViewer" to some object. Access not allowed.  tell application "System Events"     set application "KeyboardViewer" to (keystroke "K" using control down) end tell Make an object invisible to a specific camera? (Cycles) I'm trying to set up multiple cameras for a scene set in a room. Is there a way to link object visibility to a specific camera? Ideally, a wall or ceiling would not render if it were in the way of the specified camera.  I've tried to get around this by keyframing Restrict Rendering, but that gets difficult to keep track of. I've also tried adjusting the clipping plane, but that clips too much and would also need to be keyframed if the camera moves.   Thanks! How can you tell when a sunset is going to be spectacular? I have a spot that I like to take sunset pictures. I find that the most spectacular moments last for only maybe 5-10 minutes. What I would like to do is know about a half hour before that a sunset is going to be spectacular, so I can grab my camera, tripod, walk 5-10 minutes to my sunset spot, set up, and have a few minutes to spare in case something happens. However, I've often missed really cool sunsets, because I just don't know when to photograph them. How can you tell beforehand when a sunset is going to be spectacular? Thanks! I checked yesterday and today the new homepage in the Android app. Very surprised I saw that I would almost reach a silver tag badge, that confused be because I always take a look on possible badges I can get. However I compared the score with the website and I got a total different results. See this two screenshots: Where can I send feature requests? Both for Ubuntu as a whole and individual (supported) apps? Can internal forces do work? My Mechanics textbook claims that the sum of the work by internal forces is not generally zero.  translated to English the paragraph reads:     Notice about the work by internal forces: the work by the internal forces is in general not equal to zero although the sum of the internal forces is always equal to zero. Since the work also depends on the relative displacement of the two pointmasses in the material system, the work provided by these 2 internal forces will generally not be equal to zero.   Other sources claim that the work done by internal forces is always zero.  (answer by Mark Eichenlaub)     Then I didn't do any work on the system at all since, by definition, only external forces can do work.        the net work done by internal forces is zero since they do not cause motion of the object.   To me it would seem that these sources contradict eachother. Do they? If so, which one is correct? If not, please explain why they don't contradict eachother. Let $f:\Bbb{R}\to\Bbb{R}$ be a function given by  $$f(x)=\begin{cases} \exp\left(\frac{1}{x^2-1}\right) &amp; \text{if }\vert x\vert\lt 1\\  0 &amp; \text{if }\vert x\vert\geqslant 1  \end{cases}$$  I would like to prove that $f\in C^\infty$, that is, $f\in C^k$ for all $k\in \mathbb{N}$. I think that it can be done by induction on $k$. If $\vert x\vert\gt1$, the problem is trivial. On other points, the base case is the simplest and the only that I'm be able to do. Can someone help me?  Thanks.