[MySQL] NetApp DWH Query to Get Min and Max Qtree ID from an OCI server

I wrote this query because someone accidentally pointed the Annotation Import Utility at the wrong OCI server, and I was worried the wrong OCI server would have some of the same Qtree IDs and have it's annotations changed. Turns out we were lucky. A completely different range of Qtree IDs.

## Using dwh_inventory schema ##
use dwh_inventory;

## The below gets the distinct OCI_SERVER_FQDNs used in dwh_inventory.qtree ##
select distinct substring_index((substring_index(url,"/",3)),"/",-1) from qtree;

## To find the minimium and maximum QtreeID ##
## Note: This is not the DWH QtreeID, this is the QtreeID on the OCI server ##

select min(QtreeID),max(QtreeID) from
(select
  substring_index((substring_index(url,"/",3)),"/",-1) AS 'OCI Server',
  CONVERT(substring_index(url,"/",-1),UNSIGNED INTEGER) AS 'QtreeID'
from qtree
  where substring_index((substring_index(url,"/",3)),"/",-1) = 'OCI_SERVER_FQDN'
  order by 'QtreeID') as t0;


Comments