I'm not feeling well with SQL in general, and I try to accomplish a very special task First of all, I want to first run a query to get the ID of all the units of the top number of the hit, and after that to get the message, to run it again and for those IDs in those specific types All types of hits can be calculated Gets it. For the first query, I have this:
SELECT entity, as count (plugin) from plugin_status_larts is now entered as calculation () - INTERVAL '14 days' and DISC limit 10
resulting in this return:
"38792"; 3 "39416"; 2 "37796"; 2 "39145"; 2 "37713"; 2 "37360"; 2 "37724"; 2 "39152"; 2 "39 9 37"; 2 "39667"; 2
The idea is to use the result then another query that is set to run the order by the unit and the status. I tried to do something like this:
SELECT status_code, entity, COUNT (status_code) status FROM plugin_status_alerts where now updated () - INTERVAL '14 days' and now () and Unit IN (SELECT id Plugin_Status_Lets ID as Count, Count (ID.NTT): where ID is now improved between () - Interval '14 Days' and now () Group ID. According to Netity Order Count (Id.ntt) DESC limit 10) Group
but I get an error
Error: Pakuuji has too many pillars
I 'I am not sure if this path should go to me, or if I should try to join myself then either to make sure Not how it's right for how this is happening.
Use instead of IN (subquery) JOIN
/ Code>. This is usually faster, and if you need you can use additional values from the subquery (like entity
per total count): SELECT entity , Status_code, count (*) as the position sector (selection unit - not adding the count, because you do not use it, but you can be from plugin_status_larts where now () - interval '14 days' and now (group) Order (*) DESC for the antennas, by obtaining steady result Use Plgin_stet_skriy yield 10) as the tie-breaker (unit) for the area where now () - 1 by interval '14 days' and now () Group 2;
note
-
If you do not have future entries by the design, you can simplify:
< Code> WHERE entered & gt; Now () - interval '14 days'
Since the subkey returns only a single column ( entity
) with that Merge is the Usage
section, column names are clear and we do not need table qualification.
LIMIT 10
The probability of being sorted by your count is unclear. Many rows can tie for the 10th row without the extra items in ORDER BY
, postgres select arbitrarily, which can not be alright or fine, but the results of the query are done without the underlying data. Can switch between calls made. Generally, this is not desirable and you should add columns or expressions to the list in the break relationship
count (*)
. > is a bit faster than the
count, and by doing so - unless status_code
can not be redundant, in that case you will get 0 < / Code> will count for this line instead of the actual row count (
count ()
never returns to the tap), which is either useless or actively false count (* )
use either in any way
No comments:
Post a Comment