IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 11, 2026, 3:09:36 PM (2 months ago)
Author:
eugene
Message:

fix various SQL errors caught by more strict mysql versions, especially: force SQL to select a specific entry from non-aggregated fields when other fields are aggregated using e.g., GROUP BY

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-pstamp-20260421/ippTools/share/addtool_find_minidvodbrun2.sql

    r33030 r43014  
    11-- this selects the minidvodbs that have complete addRuns
    2 SELECT minidvodb_name, minidvodb_path, state, minidbg
    3 AS minidvodb_group
     2SELECT
     3  minidvodb_name,
     4  minidvodb_path,
     5  state,
     6  minidbg AS minidvodb_group
    47FROM minidvodbRun
    5 JOIN
    6    (SELECT minidvodb_name, count(state) as cnt2, cnt, minidbg, minidbn
    7    FROM addRun LEFT JOIN
    8        -- this select grabs (and counts) all the addRuns with any state
    9        -- and groups them by the name
    10        (SELECT minidvodb_group as minidbg, minidvodb_name as minidbn, count(state)
    11         AS cnt
    12         FROM addRun
    13         GROUP BY minidvodb_name )
    14    AS foo1 ON minidvodb_name = minidbn
    15         -- the second select grabs and counts all the addRuns with state
    16         -- of 'full'         
    17    WHERE addRun.state = 'full'
    18    GROUP BY minidvodb_name )
     8JOIN (
     9  SELECT
     10    minidvodb_name,
     11    count(state) AS cnt2,
     12    MIN(cnt)     AS cnt,
     13    MIN(minidbg) as minidbg,
     14    minidbn
     15  FROM addRun
     16  LEFT JOIN (
     17    -- this select grabs (and counts) all the addRuns with any state
     18    -- and groups them by the name
     19    SELECT
     20      MIN(minidvodb_group) AS minidbg,
     21      minidvodb_name AS minidbn,
     22      count(state) AS cnt
     23    FROM addRun
     24    GROUP BY minidvodb_name
     25  )
     26  AS foo1
     27  ON minidvodb_name = minidbn
     28  -- the second select grabs and counts all the addRuns with state
     29  -- of 'full'       
     30  WHERE addRun.state = 'full'
     31  GROUP BY minidvodb_name
     32)
    1933AS foo2
    2034USING(minidvodb_name)
    2135WHERE cnt2 = cnt
    22        -- the 3rd select only grabs the columns where the counts are the same
    23        -- (same number of 'full' and any state)
     36-- the 3rd select only grabs the columns where the counts are the same
     37-- (same number of 'full' and any state)
Note: See TracChangeset for help on using the changeset viewer.