Custom database queries
Options
![Georges Duverger](https://us.v-cdn.net/6037124/user_avatars/1709796.jpg)
Georges Duverger
Trusted Xano Expert ✭
I have a large table (1M+ records). I'd like to analyze it. Nothing too sophisticated but something like:
select
distinct(foo),
count(bar) as count
from
table
group by
foo
order by
count descI only see a way to define custom `where` clauses in the product. If it's not possible, I can always take the data out and figure it out but I was wondering if I was maybe missing a way to achieve something like that in Xano.
Cheers.
select
distinct(foo),
count(bar) as count
from
table
group by
foo
order by
count descI only see a way to define custom `where` clauses in the product. If it's not possible, I can always take the data out and figure it out but I was wondering if I was maybe missing a way to achieve something like that in Xano.
Cheers.
Comments
-
Hey
You can use the Query All Records function to accomplish this...
You'd change the return type to aggregate
[CleanShot 2021-09-02 at 15.40.29.png]
This will give you access to Group By, Aggregate By, and Sort By... In Aggregate By you will have access to different aggregates. For your query it sounds like you will want to use "count_distinct"
[CleanShot 2021-09-02 at 15.41.56.png]
You can still use the By Custom Query 'where' statements to do any pre-filtering that you may need. -
Oh, wow! Even time I think I'm pushing the limit, you folks already have a solution for it. I can't wait to give it a try later. Thanks for the quick response. 💪
-
Let me know if you run into any issues
-
If performance starts to get slow, you may want to add an index on anything you are filtering by. If it is a pure global aggregation then it is what it is, but if you are trying to do stats for A=B, then adding an index on A would probably speed things up.
Indexes can be added in the spreadsheet view. -
Just implemented a Grouped By and Aggregated By. So quick and straightforward. Thanks!
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback