Skip to content

Commit 5cac1ba

Browse files
committed
Filtering in a sQL select clause
1 parent c0837cc commit 5cac1ba

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

Readme.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ I blog longer form posts on Retro-Computing at [8-Bit Labs](https://8bitlabs.ca/
1111
- [C#/CSharp](#ccsharp)
1212
- [Docker](#docker)
1313
- [Electronics](#electronics)
14+
- [Git](#git)
1415
- [NeoVim](#neovim)
1516
- [PowerShell](#powershell)
1617
- [Retro Computers](#retro-computers)
1718
- [Commodore 64](#commodore-64)
1819
- [CP/M](#cpm)
20+
- [SQL](#sql)
21+
- [TypeScript](#typescript)
1922
- [WSL](#wsl)
2023
- [WinGet](#winget)
2124

@@ -28,17 +31,17 @@ I blog longer form posts on Retro-Computing at [8-Bit Labs](https://8bitlabs.ca/
2831
- [Running a Container](./docker/running-container.md)
2932
- [Attaching to a running container](./docker/attach-container.md)
3033

34+
### Electronics
35+
36+
- [SMD Resistor & Capacitor Sizes](./electronics/smd-resistors.md)
37+
3138
### Git
3239

3340
- [Revert the Last Commit](./git/revert-last-commit.md)
3441
- [View commits on all branches for a user](./git/view-user-commits.md)
3542
- [Calculate Git commits by Author on all branches in C#](./csharp/git-commits.md)
3643
- [Format the oneline output](./git/format-output.md)
3744

38-
### Electronics
39-
40-
- [SMD Resistor & Capacitor Sizes](./electronics/smd-resistors.md)
41-
4245
### NeoVim
4346

4447
- [Install NeoVim](./neovim/install-neovim.md)
@@ -61,6 +64,10 @@ I blog longer form posts on Retro-Computing at [8-Bit Labs](https://8bitlabs.ca/
6164

6265
- [ZDE16](./retro/cpm/zde16.md)
6366

67+
### SQL
68+
69+
- [Counting in a SQL Select based on the Column Value](./sql/where-in-select.md)
70+
6471
### TypeScript
6572

6673
- [Setup a Yarn Project with TypeScript in VS Code](./typescript/setup-yarn-with-ts.md)

sql/where-in-select.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Counting in a SQL Select based on the Column Value
2+
3+
I often want to count the number of a specify value in a column. I can do that in the `where` clause if it is only one value, but if I want to count more than one it doesn't work. Instead, you can filter in the `select` clause.
4+
5+
```sql
6+
select Department,
7+
count(case Position when 'Manager' then 1 else 0 end) as Managers,
8+
count(case Position when 'Employee' then 1 else 0 end) as Employees,
9+
count(case Position when 'Contractor' then 1 else 0 end) as Contractors
10+
from Employees
11+
group by Department
12+
order by Department
13+
```

0 commit comments

Comments
 (0)