Hello Surya,
You are allowed to query the sandbox databases see the guide here: https://docs.q2developer.com/setup/local/connect_sandbox_database.html
The sandbox is the exact same schema as Staging and Production there is just different data in each.
Staging and production environments are not open for you to query directly. If you need to know what is in a particular table in Staging or Production you can reach out to Q2 Support.
You may also want to pull this information via Central/Consul extension or Caliper API. https://docs.q2api.com/docs/q2-caliper-api/729542264ca31-q2-caliper-api It entirely depends on your use case and where certain data is needed.
-Trey