Is it possible in MySQL to do something like this:
SELECT COUNT(*) as totalcount, COUNT(*) WHERE foo IS NULL as conditional_count FROM baz
i.e. get two accounts, one of everything and one of the things matching the WHERE clause in one select?
This will work if your database supports the CASE WHEN statement, otherwise you will still get the main idea.
SELECT COUNT(*), SUM(CASE WHEN FOO IS NULL THEN 1 ELSE 0 END) AS COUNT_CONDITIONAL FROM baz
it should look like this: SELECT COUNT(*) as totalcount, (SELECT COUNT(*) WHERE foo IS NULL) as conditional_count FROM baz this is the only query, but with a subquery inside
SELECT COUNT(*) as totalcount, (SELECT COUNT(*) WHERE foo IS NULL) as conditional_count FROM baz
SELECT count () as totalcount, (select COUNT () FROM baz WHERE foo IS NULL) as conditional_count FROM baz;
I cannot put a star (*) between the brackets of count !!! I put it, but I canβt display it.
try with UNION (not verified)
SELECT COUNT(*) as totalcount FROM baz UNION SELECT COUNT(*) WHERE foo IS NULL as conditional_count FROM baz
I do not think that's possible. I believe you will need two queries.
Select count(*) from baz Select count(foo) from baz where foo is null
Source: https://habr.com/ru/post/889354/More articles:MVVM Light ViewModelLocator + ResourceDictionaries - wpfScheduled outage detection - windowsPHP generates pages, but doesn't immediately return them to the user - phpIs there an alternative to Java Prefuse that is under active development? - javaShow only the last 4 digits in the text field - stringSQLNonTransientConnectionException: No current connection in my application while interacting with Derby database - databaseHow can I deploy an unmanaged DLL using a click-once WPF application? - wpfQuestion about SQL insert statement! - c #Problems with matching functions of OpenCV 2.2 SURF - c ++What is the recommended way to connect the model to the controller? - iosAll Articles