0

I'm interested in how I can write mysql query if I want to count some column from table (mysql database) where that column must be chosen within another query ? like this SELECT COUNT(OTHER_QUERY) FROM TABLE

I have column named port and want to count this column within another query like this (select port where port='GCP';

I'm trying to do this task but with no result (despite of helping) I'm writing like so => SELECT COUNT(port) from data WHERE port = (select port from data where port='GCP') So I want to count column port which are equal to GCP

please help with this task :)

0

3 Answers 3

5

Just wrap the original query in a sub-select:

SELECT COUNT(A.column)
FROM (other_query) A

For your second query, I believe this should get what you want:

SELECT COUNT(A.column)
FROM (other_query) A
WHERE A.port='GCP'
Sign up to request clarification or add additional context in comments.

Comments

0

It will be like below :

Select (select count(colum_nname) from table2 )  as totalvalues from table

Comments

0

Do you want something like this :

Want total number of ports if it's value is GCP.

If so, then this is the syntax:

SELECT COUNT(port) AS alias WHERE port = GCP;

You may find this MySQL COUNT resources useful.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.