I have a question and hope you guys can assist me.
I have a table containing two columns:
type // contains 2 different values: "Raid" and "Hold"
authorization // contains 2 different values: "Accepted" or "Denied"
I need to make a view that returns values like this:
TYPE:RAID ACCEPTED:5 DENIED:7
Basically I want to know how many of the values in TYPE
are "Raid" and then how many of
them are "Accepted" and "Denied".
Thank you in advance!!
The SQL COUNT() function returns the number of rows in a table satisfying the criteria specified in the WHERE clause. It sets the number of rows or non NULL column values.
To counts all of the rows in a table, whether they contain NULL values or not, use COUNT(*). That form of the COUNT() function basically returns the number of rows in a result set returned by a SELECT statement.
SELECT COUNT (DISTINCT item_num) FROM items; If the COUNT DISTINCT function encounters NULL values, it ignores them unless every value in the specified column is NULL. If every column value is NULL, the COUNT DISTINCT function returns zero (0).
COUNT(*) returns the number of rows in a specified table, and it preserves duplicate rows. It counts each row separately. This includes rows that contain null values.
To get the number of rows that contain specific values, the generic syntax is: Array formula, should press Ctrl + Shift + Enter keys together. X: The specific value you use to count the rows. 1. Please enter or copy the below formula into a blank cell where you want to put the result: 2.
For example, to get the number of cells in A2:A10 that contain the text in D1 and handle uppercase and lowercase as different characters, use this formula: =SUMPRODUCT (--EXACT (D1, A2:A10)) Case-sensitive formula to count cells with specific text (partial match)
To get the number of rows that contain specific values, the generic syntax is: Array formula, should press Ctrl + Shift + Enter keys together. X: The specific value you use to count the rows. 1.
Specific Value: Select the value that you want to count for by changing the 'Exceldome' value in the VBA code. Worksheet Selection: Select the worksheet which captures a range of cells from which you want to count for the specific value by changing the Analysis worksheet name in the VBA code.
You can use COUNT
in combination with a CASE
statement
SELECT COUNT(CASE authorization WHEN 'denied' THEN 1 ELSE NULL END) as denied,
COUNT(CASE authorization WHEN 'authorized' THEN 1 ELSE NULL END) as authorized
FROM table
WHERE type = 'RAID'
SUM(CASE …)
is also possible, but you'll have to return 0
in the ELSE
clause instead of NULL
SELECT
Type
,sum(case Authorization when 'Accepted' then 1 else 0 end) Accepted
,sum(case Authorization when 'Denied' then 1 else 0 end) Denied
from MyTable
where Type = 'RAID'
group by Type
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With