We need to check for databases that are not in the correct compatibility level on a particular instance. For example, on a SQL Server 2016 instance, if there are databases that are not in compatibility level of 130, we need to list them. Similarly, on a SQL Server 2017, , if there are databases that are not in compatibility level of 140, we need to list them.
Take a look into the below script
SELECT name as 'Database name', compatibility_level AS 'Compatibility level', @@VERSION as 'SQL Version' FROM sys.databases S