I have 3 tables called musics, singers and playlistInfos. I want to get Top 10 listened England musics.What kind of sql query help me? SELECT * FROM musics m INNER JOIN playlistInfo p ON p.musicID = m.id INNER JOIN singer a ON a.id = m.singerID GROUP BY p.musicID ORDER BY p.listened I try this one but I did not get
Tag: group-by
Select values for a column only if there are no rows with that value that satisfy a condition
I have a table that stores logs of http fetches, let’s say we have two columns: fetch_url and success. A few example rows: success fetch_url TRUE A FALSE A FALSE B FALSE B FALSE …
Selecting first element in Group by object Postgres
I have the following table and I want to get the specidic Amount per loan_ID that corresponds to the earliest observation with greater than or equal to 10 dpd per month. The expected output: Answer Returns: Loan_ID month Amount 1 2017-01-01 50000 2 2017-01-01 8784 You can find test case in db<>fiddle
SQL query for checking whether a column with a specific value has its correspondent row with another specific value in the same column
I am not completely sure how to solve this problem. My data looks like this: And I would like to see whether L_TYPE 673 has no correct correspondent with L_TYPE = 660. I want to find out whether the column L_TYPE with the value 673 has also its correspondent 660. All the other values do not change. However, I would
Create SQL statement with mulitple AND
I have a problem with creating right SQL request. This is my table: I would like to display all items that: -Are in warehouse A in number less than 2 -Are in watehouse B in number grater than 0 At the same time. I would expect item1 will be displayed. My code so far is: I know that warehouse =
SQL Query to find a group of rows having all of them a certain value in one of its fields
Given table: +—+——-+——+—+ |id | attr | fker |did| +—+——-+——+—+ |1 | attr1 | 5 | 1| |2 | attr1 | 17 | 1| |3 | attr1 | 3 | 2| |4 | attr2 | 31 | 2| |5 | attr2 |…
How to remove “not a GROUP BY expression” error from the statement?
The schema of the table is: Emp (Empno, Ename, Job, Mgr, Hiredate, Sal, Comm, Deptno) Question: Display the job, deptno and average salary of employees belonging to department 10 or 20 and their salary is more than 2000 and average salary is more than 2500. My Query: Error: ORA-00979: not a GROUP BY expression I cannot find what is wrong
Aggregation level is off (Postgresql)
I have Order data for 2 customers and their order. And I am trying to calculate what the sum for the price is for every customter for that specific order only for product N Table: This is my query: For some reason I do not understand it gives me several rows per same customer. I am trying to get only
MySQL Merge two queries based on mutual column
I have two queries that retrieve records from 2 different tables that are almost alike and I need to merge them together. Both have created_date which is of type datetime and I’m casting this column to date because I want to group and order them by date only, I don’t need the time. First query: Second query: What I need
SQL how to select a single value from a table with LEFT JOIN, In Google Datastudio
I have two tables one table called mailing_events and one table called mailing_outletcontact. Examples of my tables are below. The mailing table is very simple with no duplicates: My Second table “mailing_outletcontact” has duplicates in the email field. I am trying to query the database in Datastudio with my goal being to get the “outletcontact_id” field with my first table