Useful Metric/Statics

AI-generated summary

In a discussion titled ‘Useful Metric/Statics’ under the ‘Data & reporting’ category, hhlp is seeking help locating useful SQL queries previously shared on Discourse. Johani responds by directing them to two relevant topics: one on cool Data Explorer queries and another on cool badge queries. Mittineague adds that while it’s possible to run ActiveRecord queries via the Ruby console, the Data Explorer plugin is the recommended and safer method. They highlight its advantages: it displays table/field information, restricts to SELECT queries (preventing destructive actions), and includes built-in LIMIT to avoid site crashes. Mittineague notes that while some understanding of the database structure is helpful — such as recognizing that posts.topic_id references topics.id — many queries are intuitive to construct.

I read somewhere here in discourse but now I can’t find it, a post where someone write a usefull metric/static with SQL Query… there are a few, what I would like to use…

Could you point me out…

Regards.,

There are a couple of topics that relate to this:

  1. Data explorer queries
  1. Badge queries

It is possible to enter the ruby console and run ActiveRecord queries, if you feel more comfortable doing that.

But IMHO, the best way is to use the Data Explorer plugin.

  • it provides information about tables, fields, and field datatypes
  • it does only SELECT queries so it is inherently safer because it can not do anything destructive
  • has built in LIMIT so a poorly crafted query will not bog or crash your site

Some knowledge of the database architecture is still needed, especially for complex queries. But many (IMHO, most) times it is intuitive. eg.
it is clear that the posts table’s posts.topic_id field references the topics table’s topics.id field.