I’m pretty new in the SQL world and i have some troubles about counting some row. I explain myself: I have a DB like this: NAME | (somenumbers)| L1 | 2 L1 | 2 L2 | 3 L3 | 1 L3 | 1 L3 | 1 …
Tag: group-by
Getting date, and count of unique customers when first order was placed
I have a table called orders that looks like this: And that contains the following data: I would like a result set returning each unique date, and a separate column showing how many customers that placed their first order that day. I’m having problems with querying this the right way, especially when the data consists of multiple orders the same
SQL count column from another table
I have two tables in a database The first being people which has the columns id: int, name: varchar(10) and another being relationships which represents a one way following me: int following: int …
Aggregation of Json objects on a relational table on Postgres
I have a relational table that contains three variable values, an ID, and the date broken down into parts. ID | Year | Month | Day | A | B | C | 1 2019 12 01 5 10 15 1 2019 …
SQL sequent grouped rows
+——+——+——+————+ | id | room | type | created_at | +——+——+——+————+ | 8214*| 83 | msg* | 1571726466 | | 8213 | 83 | msg* | 1571724983 | | 8212 | 83 | ad …
mysql error “ Operand should contain 1 column(s)” when count occurrences in multiple columns
I want to get occurrences in multiple columns and count null values as zeros. I have tried this. select IFNULL((select id, count(*) as v from ( select id, s1 as val from t1 …
SQL group two value in a same row
I have this query SELECT to_char(timestamp_arr,’Dy DD/MM/YYYY’) as timestamp_date ,to_char(timestamp_arr,’DD/MM/YYYY’) as link_date ,count(transport_uid) as value ,…
SQL change a table into another format
I have a table like this: Faculty Program Number_of_enrolled Science Financial Modelling 25 Science Actuarial Science 30 Science Statistics 28 Science Biology …
How to use order by after group by sql
I have a table like this: and I need to group by and order on positionNr. I tried with this query: But I obtain something like this: But what I want is a result like this: Please can you help to understand where is the problem on the query? Answer Based on your expected result, it seems that: 1- You
SQL – get distinct values and its frequency count of occurring in a group
I have a table data as: The data set is as follows: I need to list all distinct search_product_result values and count frequencies of these values occurring in s_product_id. Required Output result-set: Here, A occurs in three s_product_id : 0, 1, 2, B in two : 0, 2, and so on. D occurred twice in the same group 3, but