Questions tagged [conditional-aggregation]
86 questions
0
votes
2 answers
MySql query to find difference between same column with condition
I have this table register:
id quantity type
1 | 10 | in
2 | 5 | in
1 | 3 | out
1 | 2 | out
2 | 5 | out
3 | 2 | in
3 | 1 | out
I want the balance of each stock *sum of type='in' - sum of type=…

Sourav
- 17,065
- 35
- 101
- 159
0
votes
2 answers
how to apply filter to each row after the group by in sql
i have a table -
Table=emp
eno ename designation sal mgr deptno
1 aaa salesman 7000 2 10
2 bbb manager 17000 3 10
3 ccc president 40000 null 30
4 ddd clerk 5000 5 20
5 eee manager 20000 3 …
0
votes
1 answer
PLSQL Querying one variable and spliting into two column
So I have a table called Table1, with two columns, Product, and indicator.
Table1
Product Indicator
Product 1 Y
Product 1 Y
Product 1 Y
Product 1 N
Product 1 N
Product 2 Y
Product 2 Y
Product 2 Y
Product 2 …

Oxy111
- 67
- 1
- 7
0
votes
3 answers
SQL query to group user activity based on time range
I have a table with two columns, id and modifiedDate. I want to query this table to list each id's activity between a time range.
My table looks like:
+-----+------------+
| ID | Date |
+-----+------------+
| 1 | 2017.01.19 |
| 1 |…

user2838877
- 1
- 3
0
votes
1 answer
Select in Postgres with case
I'm trying to make the following consult:
Managers | Clerks | Presidents | Analysts | Salesmans
-------------+---------+--------------+ -----------+-------------
3 4 1 2 4
So…
user7128116
0
votes
1 answer
Postgresql SQL to find revenue from different department on invoice number
I need to find the doctors revenue from various departments like laboratory,radiology,pharmacy and other departments trough patients.
I have only document_number column where the values recorded as 'L1432','R87j7','P652', etc. if doc_no starts with…

Abdur Rahmaan
- 29
- 4
0
votes
2 answers
How to have one row multiple columns instead of multiple rows
I have the following data:
In SQL Server How can I have group by weekdate so I have only one row for each weekdate, example for the weekdate 2015-11-14:
Any clue?

VAAA
- 14,531
- 28
- 130
- 253
-1
votes
2 answers
Filter as count on SQL SERVER
Helo!
How I make the following syntax of postgresql in SQL server without create subquery
PGSQL:
SELECT
COUNT(*) AS "QUANTIDADE TOTAL",
COUNT(*) FILTER(WHERE SEXO = 'Masculino') AS "MASCULINO"
FROM FUNCIONARIOS;
I tried but got an…

Ricardo Luiz Vieira
- 13
- 1
-1
votes
2 answers
Can I get two count results in a query?
I am using MariaDB. I want to have two count results in a query.
The first query is:
SELECT
license_key,
COUNT( * ) AS expired
FROM license_product
WHERE expire_at > NOW()
GROUP BY license_key;
Next is:
SELECT
license_key,
…

seunghyeon
- 1
- 3
-1
votes
1 answer
How to remove NULL from case when and then output Oracle SQL Developer
Oracle SQL Developer noob here. I am trying to create a quarterly sales analysis based on warehouse names and output the Quarterly sales as Q1, Q2 etc. Using Drill down query concepts.
I am unsure if what I am doing is in any way related to a Drill…

DalCipher
- 9
- 2
-1
votes
1 answer