• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Find Total Occurrence of a Variable Based on Another Variable in SQL

Resolved: Find Total Occurrence of a Variable Based on Another Variable in SQL

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I’m trying to provide a SQL query to find which XNumbers had the most YNumbers. Here is my data:
Here is what I’ve tried:
The result comes back as a row of just 1s, which isn’t correct.
Desired output would be a SELECT statement that answers the question: Which XNumbers had the most YNumbers?

Answer:

For each “Xnumber”, you want to count the “YNumber”, so just count “YNumber” and group by “Xnumber”.
Since you only need the most “YNumber”s, use RANK() function.
See db<>fiddle

If you have better answer, please add a comment about this, thank you!

greatest-n-per-group sql
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How can I copy files using the ansible.builtin.copy module and avoid conflicting file names?

26/03/2023

Resolved: Reshape tensors of unknown shape with tf.function

26/03/2023

Resolved: Use Svelte Component as Slot

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.