This topic provides examples of SQL query statements that you can use to search for resources.
- Example 1: Search for all Elastic Compute Service (ECS) instances that have the
business:online
tag and reside in the China (Shanghai) region.In this example, the following SQL statement is used:SELECT ResourceId, ResourceName WHERE ResourceType='ACS::ECS::Instance' AND RegionId='cn-shanghai' AND Tags.Kvpair='business:online'
Note Tags are in the format ofKey:Value
. - Example 2: Search for all ECS instances that have the
product
tag and 1 GB of memory.In this example, the following SQL statement is used:SELECT COUNT(1) WHERE ResourceType='ACS::ECS::Instance' AND Memory=1024 AND Tags.Key='product'
- Example 3: Search for all ECS instances that are created after the time specified
by
2021-01-01 00:00:00
.In this example, the following SQL statement is used:SELECT ResourceId, ResourceName WHERE ResourceType = 'ACS::ECS::Instance' AND ResourceCreationTime > '2021-01-01 00:00:00'
- Example 4: Search for the elastic network interface (ENI) of an ECS instance whose
IPv4 address is
198.168.XX.XX
.In this example, the following SQL statement is used:SELECT * WHERE ResourceType = 'ACS::ECS::NetworkInterface' AND PrivateIpAddress = '198.168.XX.XX'
- Example 5: Query the number of resources of each resource type.
In this example, the following SQL statement is used:
SELECT ResourceType, COUNT(1) GROUP BY ResourceType ORDER BY COUNT(1) DESC