Query to find the second highest row in a subquery

The goal is to send notifications about the customer updates but only for the first one if there are consecutive updates from the customer in a ticketing system.

This is the simplified query that I’m using to get the data that I need. There are a few more columns in the original query and this subquery for threads is kind of required so I can also identify if this is a new ticket or if existing one was updated (in case of update, the role for the latest threads will be a customer):

SELECT t.ref, m.role    FROM tickets t    LEFT JOIN threads th ON (t.id = th.ticket_id)    LEFT JOIN members m ON (th.member_id = m.id)   WHERE th.id IN ( SELECT MAX(id)                      FROM threads                     WHERE ticket_id = t.id                 ) 

It will return a list of tickets so the app can send notifications based on that:

+------------+----------+ | ref        | role     | +------------+----------+ | 210117-001 | customer | | 210117-002 | staff    | +------------+----------+ 

Now, I want to send only a single notification if there a multiply consecutive updates from the customer.


How I can pull last and also one before last row to identify if this is consecutive reply from the customer?

I was thinking about GROUP_CONCAT and then parse the output in the app but tickets can have many threads so that’s not optimal and there are also a few more fields in the query so it will violate the ONLY_FULL_GROUP_BY SQL mode.

db<>fiddle here

What’s the highest critical hit damage a level 1 character can do?

What’s the highest critical hit damage a level 1 character can do?


  • The character must be level 1
  • The character cannot have any magical items
  • The character’s starting equipment must be affordable with the standard 15 gp start
  • The character can be assisted by up to three other level 1 characters with the same restrictions
  • The three assistant characters each have one round before the primary character makes their attack
  • The damage must come off of one critical hit (i.e. the first hit of Flurry of Blows, not both)
  • Max damage can be assumed

What is the highest armour class possible for an Ancient Green dragon?

This posts asks what the highest armour class may be for humanoids. Similar to this question, i would like to know what the highest AC would be for a monster. Narrowing this down, let us look at improvement techniques possible for an ancient Green dragon. As this is a BBED (‘Big Bad Evil Dragon’), they most likely have a slew of minions, guardians and servants – so please feel free to use any options that exist (in 5e) that may be spells, minions, a spare shield guardian, or anything else you like.

For stats on the ancient Green dragon, has a base dexterity of 12 and a base AC of 21. I do not know if it could gain NPC levels of monk or barbarian, nor what use that would have. We can assume this dragon has the ‘optional’ spell casting abilities. According to old (possibly 3.5e) Forgotten Realms material these creatures are a minimum of 800 years old at ‘ancient’ and may live until past 1,200 years or more. They seem to have access to a lot of magic items. These things are gargantuan, so i have no idea, for example, what size shield they would need – or even if a shield works for them. I don’t even know how big ‘cover’ would need to be in order to offer 3/4 protection. Would a Cloak of Protection even fit? I have specifically left this quite open as i would greatly value any and all possibilities that Stack Exchange has to offer.

Let me know if this question is specific enough. The original (above) was seemingly less specific, but Stack Exchange seemed to be enjoying a different mindset at that time.

Question Recap: What is the best armour class possible for a 5e ancient Green dragon – assuming any & all options are available to it.

What is the highest average charisma skill check a solo character can get, without using magic?

I was building a character that had levels in Feywanderer ranger, that gains Otherworldly Glamour which allows you to add wisdom to charisma checks, and then I noticed Samurai fighters get Elegant Courtier which has the same bonus.

Emboldened by the fact they stack, I started to look for other class features that let you reroll failed intimidation checks or gain advantage.

It made me wonder, what is the highest possible charisma skill check by a solo character?

(This means no spells, or magic items and no outside assistance except by summoned/created creatures, e.g. a familiar using the help action is ok, but a party member using flash of genius is not.).

What happens if you reroll and the new highest die is lower than the original?

I was reading the Cthulhu Dark rules again, and I noticed something that wasn’t specified.

The section on rerolling says, in part:

If you included your Insanity die in the roll and you’re not happy with the result, you may reroll (all the dice). If you didn’t include your Insanity die before, you may add it now and reroll.

Afterwards, look at the new result. As before, the highest die shows how well you do.

It does not say anything about what happens if the highest die after rerolling is lower than the highest die before the reroll. Do you still use the new roll if the highest die is lower than the higher die before rerolling?

What is the highest minimum and maximum roll possible on a (Dex) sleight of hand/pickpocket check? [closed]


Let’s say we’re attempting to pickpocket something from someone and would like to reduce our chances of failure as much as possible. What is the highest minimum roll and maximum roll reliably possible in the game? In order to make this easier to replicate for others, I’m going to offer some restrictions:

  • Things that are not largely guaranteed in most games, such as: Boons, Artifacts, and Manuals.
  • This can be any level character up to 20th level, all that matters is that it still remains the highest min and max roll for the check.
  • Must be acting alone and receive assistance only from themselves, their items, feats, racial abilities, class features, etc.

These restrictions should ensure that the check can be performed reliably any time it is made by anyone with the proposed build in nearly any campaign with the average amount of magical items and quest rewards, etc.

I will post my own findings as an answer below. Feel free to use it as a frame for further answers, or offer one all your own.

What is the highest value a condition could reach?

I’m making a Pathfinder 2e character sheet on Google sheet to automate as much number-crunching as possible. Currently, I’m making a dropdown list for conditions, as well as formulas for calculating their penalties.

I find adding conditions with pre-determined values much simpler than conditions with fillable values. For example, instead of clumsy and a blank slot for its value, the dropdown list will have clumsy 1, clumsy 2, clumsy 3, and so on. It’s ugly, but it greatly simplifies the formula. However, if a condition’s value could reach a really high number, then it will be too cumbersome to use.

The highest I have found is stupefied 4 from feeblemind and unfathomable song. I’m also pretty sure I’ve seen an ancestry/heritage/feat which could increase the maximum value of dying to 5.

So what is the highest value/penalty a condition could reach? For the supremely meticulous: what is the highest value each condition could reach?

Whats the highest racial or template charisma boost you can get for a +1 LA?

I’m currently working on a Sha’ir Gish character that will eventually PrC into Zhentarim Skymage(LoD) and I need to buff my charisma as much as possible. Skymage has a gimmick of giving you a paladin mount, or at least a close facially thereof, which can be any creature that’s a size larger than you and has no more hit die than your Skymage level + Charisma mod + 1. I already have Spark(Dragon Mag) for +2. I’m also considering Prestige Races (also Dragon) for another +1. Unseelie Fey is unfortunately banned so that’s not an option. Other than that just about anything official is allowed. I’d prefer to stay at or below LA +1 is possible. Some other options i considered were Athasian Human (also Dragon mag) +2 to two stats, Draconic Creature for +2 to strength, con, and charisma, and savage progression half fey. Spark was ruled to only work on PHB races and not variants like Athasian so that’s probably off the table, and it kind of negates the benefits of any +2 charisma LA 0 race like Spellscale and Savage Progression Aasimar.

I could use magic items like tomes eventually to raise it farther, but i can’t rely on temporary boosts like cloaks of charisma because if my charisma gets lowered, like taking the cloak off, my mount might rebell and attack or abandon me, and that’s not fun for anyone. I’d prefer human for story reasons in the setting and to open up Human paragon as an option for another +2 untyped bonus, though small races aren’t a bad choice either because that opens up a medium mount. I’m aiming for a Wyvern to be my first mount with a True dragon of some kind as my final. Mostly likely a 11-14 hit dice gold dragon for general power and the ability to turn into a smaller animal for easy transportation. Though if anyone want’s to make a better suggestion id be happy to hear it.

Why is the Halting problem decidable for Goto languages limited on the highest value of constants and variables?

This is taken from an old exam of my university that I am using to prepare myself for the coming exam:

Given is a language $ \text{Goto}_{17}^c \subseteq \text{Goto}$ . This language contains exactly those $ \text{Goto}$ programs in which no constant is ever above $ 17$ nor any variable ever above $ c$ .

$ Goto$ here describes the set of all programs written in the $ Goto$ language made up of the following elements:

With variables $ v_i \in \mathbb{N}$ and constants $ c \in \mathbb{N}$
Assignment: $ x_i := c, x_i := x_i \pm c$
Conditional Jump: if(Comparison) goto $ L_i$
Haltcommand: halt

I am currently struggling with the formalization of a proof, but this is what I have come to so far, phrased very casually: For any given program in this set we know that it is finite. A finite program contains a finite amount of variables and a finite amount of states, or lines to be in. As such, there is a finite amount of configurations in which this process can be. If we let this program run, we can keep a list of all configurations we have seen. That is, the combination of all used variable-values and the state of the program. If we let the program run, there must be one of two things that happens eventually: The program halts. In this case, we return YES and have decided that it halts. The program reaches a configuration that has been recorded before. As the language is deterministic, this means that we must have gone a full loop which will exactly repeat now.

No other case can exist as that would mean that we keep running forever on finite code without repeating a configuration. This means after every step, among our list of infinite steps, there is a new configuration. This would mean that there are infinite configurations, which is a contradiction.

Is this correct? Furthermore, how would a more formal proof look if it is? If not, how would a correct proof look?

How to get the registers in the highest time of period

I have 2 tables all with relations and i want to get the contracts in the highest time of period in order to do a hystorical report wheter if the tima of period is closed or active

This is the code that i have or that ive been trying

Select a.id, a.ordinalperiod,b.name, a.fecin,a.fecend,b.dtend,a.contrato

From historiccontrat a Left join periodo b On a.id=b.id And a.ordinalperiod=b.ordinalperiod Where a.fecend in(select max(b.dtend)where a.id=b.id and a.ordinalperiod=b.ordinalperiod and b.dtend <>’4000-01-01′)

Th thing is that the employee have 5 period of times taht works in the company liket this

Id período dt_start dt_end 000 1 2012-01-01 2012-04-01

000 2 2013-05-01 2016-04-03

…. …. ….

And in each of these períods of time have diferente type of contrats

With this say what i want is that the filter show me Just the contrats in the Last period

But the result with my query is the row with the data of the period 2 but no the contrats

Thank for your help