How to get multiple states by one sql/ api/ ...?

Hey guys,
I’m struggling big time to get necessary data from DB states table.

I tried by using Rest API - /api/states/<entity_id>. Would be fine but it returns only 1 result.
I tried to write sensor using SQL within ` - platform: sql. Would be nice, but it allows only 1 row as well. And if I try to write query with Limit more than 1 - I don’t have any records.

Question: HOW should I get last X rows from states table and how to use them in an array as state objects. I.e. In a perfect use I could use API with criteria OR query like this:

SELECT * FROM 'states' where domain = 'YYY' and state = 'ZZZ' and entity_id = 'XXX' order by created desc limit 10;

How do you use that? How do you show that in lovelace?