SQL : Find Numbers of Rows in a Table according to Criteria
I want to get numbers of rows in a table according to certain criteria.
Please see the below table:-
Herein I want to get numbers of rows according to Column StationTo.
I want to get numbers of rows of each StationTo entries.
sql select
|
show 4 more comments
I want to get numbers of rows in a table according to certain criteria.
Please see the below table:-
Herein I want to get numbers of rows according to Column StationTo.
I want to get numbers of rows of each StationTo entries.
sql select
1
Hint :select StationTo, count(*) ... group by StationTo
– Barbaros Özhan
Nov 20 '18 at 19:13
1
Possible duplicate of SQL: How to get the count of each distinct value in a column?
– JNevill
Nov 20 '18 at 19:14
@BarbarosÖzhan Inserting StationTo data should give me number of rows only.
– Mohit Kumar
Nov 20 '18 at 19:22
@JNevill Same as above
– Mohit Kumar
Nov 20 '18 at 19:22
1
select count(*) from tablename where StationTo = 'P11004400000'
– jarlh
Nov 20 '18 at 19:29
|
show 4 more comments
I want to get numbers of rows in a table according to certain criteria.
Please see the below table:-
Herein I want to get numbers of rows according to Column StationTo.
I want to get numbers of rows of each StationTo entries.
sql select
I want to get numbers of rows in a table according to certain criteria.
Please see the below table:-
Herein I want to get numbers of rows according to Column StationTo.
I want to get numbers of rows of each StationTo entries.
sql select
sql select
edited Nov 20 '18 at 20:25
Mureinik
179k22130198
179k22130198
asked Nov 20 '18 at 19:10
Mohit Kumar
63
63
1
Hint :select StationTo, count(*) ... group by StationTo
– Barbaros Özhan
Nov 20 '18 at 19:13
1
Possible duplicate of SQL: How to get the count of each distinct value in a column?
– JNevill
Nov 20 '18 at 19:14
@BarbarosÖzhan Inserting StationTo data should give me number of rows only.
– Mohit Kumar
Nov 20 '18 at 19:22
@JNevill Same as above
– Mohit Kumar
Nov 20 '18 at 19:22
1
select count(*) from tablename where StationTo = 'P11004400000'
– jarlh
Nov 20 '18 at 19:29
|
show 4 more comments
1
Hint :select StationTo, count(*) ... group by StationTo
– Barbaros Özhan
Nov 20 '18 at 19:13
1
Possible duplicate of SQL: How to get the count of each distinct value in a column?
– JNevill
Nov 20 '18 at 19:14
@BarbarosÖzhan Inserting StationTo data should give me number of rows only.
– Mohit Kumar
Nov 20 '18 at 19:22
@JNevill Same as above
– Mohit Kumar
Nov 20 '18 at 19:22
1
select count(*) from tablename where StationTo = 'P11004400000'
– jarlh
Nov 20 '18 at 19:29
1
1
Hint :
select StationTo, count(*) ... group by StationTo
– Barbaros Özhan
Nov 20 '18 at 19:13
Hint :
select StationTo, count(*) ... group by StationTo
– Barbaros Özhan
Nov 20 '18 at 19:13
1
1
Possible duplicate of SQL: How to get the count of each distinct value in a column?
– JNevill
Nov 20 '18 at 19:14
Possible duplicate of SQL: How to get the count of each distinct value in a column?
– JNevill
Nov 20 '18 at 19:14
@BarbarosÖzhan Inserting StationTo data should give me number of rows only.
– Mohit Kumar
Nov 20 '18 at 19:22
@BarbarosÖzhan Inserting StationTo data should give me number of rows only.
– Mohit Kumar
Nov 20 '18 at 19:22
@JNevill Same as above
– Mohit Kumar
Nov 20 '18 at 19:22
@JNevill Same as above
– Mohit Kumar
Nov 20 '18 at 19:22
1
1
select count(*) from tablename where StationTo = 'P11004400000'
– jarlh
Nov 20 '18 at 19:29
select count(*) from tablename where StationTo = 'P11004400000'
– jarlh
Nov 20 '18 at 19:29
|
show 4 more comments
3 Answers
3
active
oldest
votes
You could group by the StationTo
and use the aggregate count(*)
function:
SELECT StationTo, COUNT(*)
FROM mytable
GROUP BY StationTo
EDIT:
If you just want the number of rows for a single StationTo
, you could use a where
clause:
SELECT COUNT(*)
FROM mytable
WHERE StationTo = 'P11004400000'
I only want to get number of rows for a particular entry of StationTo (Column). I would be searching by StationTo code number e.g. by P11004400000. Inserting P11004400000 should give me number of rows only.
– Mohit Kumar
Nov 20 '18 at 19:15
@MohitKumar You could use a simplewhere
clause - see my edited answer
– Mureinik
Nov 20 '18 at 19:57
Ya nearly there. I want to apply date condition also. How can we do so ?
– Mohit Kumar
Nov 20 '18 at 20:41
add a comment |
Hi have you master table for stationTo records?
select s.stationto, count(data.*) from stationtomaster
left join data on data.stationto=stationtomaster.stationto
group by s.stationto
add a comment |
Select StationTo,Date, count(*) from table group by StationTo, Date
meaning all the stationTo having rows display their count.
or select count(distinct StationTo) from table
or Select count(*) from table where stationTo='yourvalue'
I want to add one condition also, that is to filter date. The TDate Column has date as well as time. What if i want count of date 20/11/17, what to do about time entries (like 02:28, see TDate column) suffixing with the date entry ?
– Mohit Kumar
Nov 20 '18 at 21:20
include date in group by if that is also same itll make a group for stationto on same date.
– Himanshu Ahuja
Nov 20 '18 at 21:25
how to do that ?
– Mohit Kumar
Nov 20 '18 at 21:36
check my answer first query again i have edited
– Himanshu Ahuja
Nov 20 '18 at 21:40
Grouping is working. But what if i only want count of rows. The TDate has date and time both, how to search for that ? I have tried LIKE function using TDate LIKE '%20/11/2018%', but failed.
– Mohit Kumar
Nov 20 '18 at 21:49
|
show 4 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399939%2fsql-find-numbers-of-rows-in-a-table-according-to-criteria%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could group by the StationTo
and use the aggregate count(*)
function:
SELECT StationTo, COUNT(*)
FROM mytable
GROUP BY StationTo
EDIT:
If you just want the number of rows for a single StationTo
, you could use a where
clause:
SELECT COUNT(*)
FROM mytable
WHERE StationTo = 'P11004400000'
I only want to get number of rows for a particular entry of StationTo (Column). I would be searching by StationTo code number e.g. by P11004400000. Inserting P11004400000 should give me number of rows only.
– Mohit Kumar
Nov 20 '18 at 19:15
@MohitKumar You could use a simplewhere
clause - see my edited answer
– Mureinik
Nov 20 '18 at 19:57
Ya nearly there. I want to apply date condition also. How can we do so ?
– Mohit Kumar
Nov 20 '18 at 20:41
add a comment |
You could group by the StationTo
and use the aggregate count(*)
function:
SELECT StationTo, COUNT(*)
FROM mytable
GROUP BY StationTo
EDIT:
If you just want the number of rows for a single StationTo
, you could use a where
clause:
SELECT COUNT(*)
FROM mytable
WHERE StationTo = 'P11004400000'
I only want to get number of rows for a particular entry of StationTo (Column). I would be searching by StationTo code number e.g. by P11004400000. Inserting P11004400000 should give me number of rows only.
– Mohit Kumar
Nov 20 '18 at 19:15
@MohitKumar You could use a simplewhere
clause - see my edited answer
– Mureinik
Nov 20 '18 at 19:57
Ya nearly there. I want to apply date condition also. How can we do so ?
– Mohit Kumar
Nov 20 '18 at 20:41
add a comment |
You could group by the StationTo
and use the aggregate count(*)
function:
SELECT StationTo, COUNT(*)
FROM mytable
GROUP BY StationTo
EDIT:
If you just want the number of rows for a single StationTo
, you could use a where
clause:
SELECT COUNT(*)
FROM mytable
WHERE StationTo = 'P11004400000'
You could group by the StationTo
and use the aggregate count(*)
function:
SELECT StationTo, COUNT(*)
FROM mytable
GROUP BY StationTo
EDIT:
If you just want the number of rows for a single StationTo
, you could use a where
clause:
SELECT COUNT(*)
FROM mytable
WHERE StationTo = 'P11004400000'
edited Nov 20 '18 at 19:57
answered Nov 20 '18 at 19:13
Mureinik
179k22130198
179k22130198
I only want to get number of rows for a particular entry of StationTo (Column). I would be searching by StationTo code number e.g. by P11004400000. Inserting P11004400000 should give me number of rows only.
– Mohit Kumar
Nov 20 '18 at 19:15
@MohitKumar You could use a simplewhere
clause - see my edited answer
– Mureinik
Nov 20 '18 at 19:57
Ya nearly there. I want to apply date condition also. How can we do so ?
– Mohit Kumar
Nov 20 '18 at 20:41
add a comment |
I only want to get number of rows for a particular entry of StationTo (Column). I would be searching by StationTo code number e.g. by P11004400000. Inserting P11004400000 should give me number of rows only.
– Mohit Kumar
Nov 20 '18 at 19:15
@MohitKumar You could use a simplewhere
clause - see my edited answer
– Mureinik
Nov 20 '18 at 19:57
Ya nearly there. I want to apply date condition also. How can we do so ?
– Mohit Kumar
Nov 20 '18 at 20:41
I only want to get number of rows for a particular entry of StationTo (Column). I would be searching by StationTo code number e.g. by P11004400000. Inserting P11004400000 should give me number of rows only.
– Mohit Kumar
Nov 20 '18 at 19:15
I only want to get number of rows for a particular entry of StationTo (Column). I would be searching by StationTo code number e.g. by P11004400000. Inserting P11004400000 should give me number of rows only.
– Mohit Kumar
Nov 20 '18 at 19:15
@MohitKumar You could use a simple
where
clause - see my edited answer– Mureinik
Nov 20 '18 at 19:57
@MohitKumar You could use a simple
where
clause - see my edited answer– Mureinik
Nov 20 '18 at 19:57
Ya nearly there. I want to apply date condition also. How can we do so ?
– Mohit Kumar
Nov 20 '18 at 20:41
Ya nearly there. I want to apply date condition also. How can we do so ?
– Mohit Kumar
Nov 20 '18 at 20:41
add a comment |
Hi have you master table for stationTo records?
select s.stationto, count(data.*) from stationtomaster
left join data on data.stationto=stationtomaster.stationto
group by s.stationto
add a comment |
Hi have you master table for stationTo records?
select s.stationto, count(data.*) from stationtomaster
left join data on data.stationto=stationtomaster.stationto
group by s.stationto
add a comment |
Hi have you master table for stationTo records?
select s.stationto, count(data.*) from stationtomaster
left join data on data.stationto=stationtomaster.stationto
group by s.stationto
Hi have you master table for stationTo records?
select s.stationto, count(data.*) from stationtomaster
left join data on data.stationto=stationtomaster.stationto
group by s.stationto
answered Nov 20 '18 at 19:43
László Tóth
765
765
add a comment |
add a comment |
Select StationTo,Date, count(*) from table group by StationTo, Date
meaning all the stationTo having rows display their count.
or select count(distinct StationTo) from table
or Select count(*) from table where stationTo='yourvalue'
I want to add one condition also, that is to filter date. The TDate Column has date as well as time. What if i want count of date 20/11/17, what to do about time entries (like 02:28, see TDate column) suffixing with the date entry ?
– Mohit Kumar
Nov 20 '18 at 21:20
include date in group by if that is also same itll make a group for stationto on same date.
– Himanshu Ahuja
Nov 20 '18 at 21:25
how to do that ?
– Mohit Kumar
Nov 20 '18 at 21:36
check my answer first query again i have edited
– Himanshu Ahuja
Nov 20 '18 at 21:40
Grouping is working. But what if i only want count of rows. The TDate has date and time both, how to search for that ? I have tried LIKE function using TDate LIKE '%20/11/2018%', but failed.
– Mohit Kumar
Nov 20 '18 at 21:49
|
show 4 more comments
Select StationTo,Date, count(*) from table group by StationTo, Date
meaning all the stationTo having rows display their count.
or select count(distinct StationTo) from table
or Select count(*) from table where stationTo='yourvalue'
I want to add one condition also, that is to filter date. The TDate Column has date as well as time. What if i want count of date 20/11/17, what to do about time entries (like 02:28, see TDate column) suffixing with the date entry ?
– Mohit Kumar
Nov 20 '18 at 21:20
include date in group by if that is also same itll make a group for stationto on same date.
– Himanshu Ahuja
Nov 20 '18 at 21:25
how to do that ?
– Mohit Kumar
Nov 20 '18 at 21:36
check my answer first query again i have edited
– Himanshu Ahuja
Nov 20 '18 at 21:40
Grouping is working. But what if i only want count of rows. The TDate has date and time both, how to search for that ? I have tried LIKE function using TDate LIKE '%20/11/2018%', but failed.
– Mohit Kumar
Nov 20 '18 at 21:49
|
show 4 more comments
Select StationTo,Date, count(*) from table group by StationTo, Date
meaning all the stationTo having rows display their count.
or select count(distinct StationTo) from table
or Select count(*) from table where stationTo='yourvalue'
Select StationTo,Date, count(*) from table group by StationTo, Date
meaning all the stationTo having rows display their count.
or select count(distinct StationTo) from table
or Select count(*) from table where stationTo='yourvalue'
edited Nov 20 '18 at 21:25
answered Nov 20 '18 at 19:29
Himanshu Ahuja
509216
509216
I want to add one condition also, that is to filter date. The TDate Column has date as well as time. What if i want count of date 20/11/17, what to do about time entries (like 02:28, see TDate column) suffixing with the date entry ?
– Mohit Kumar
Nov 20 '18 at 21:20
include date in group by if that is also same itll make a group for stationto on same date.
– Himanshu Ahuja
Nov 20 '18 at 21:25
how to do that ?
– Mohit Kumar
Nov 20 '18 at 21:36
check my answer first query again i have edited
– Himanshu Ahuja
Nov 20 '18 at 21:40
Grouping is working. But what if i only want count of rows. The TDate has date and time both, how to search for that ? I have tried LIKE function using TDate LIKE '%20/11/2018%', but failed.
– Mohit Kumar
Nov 20 '18 at 21:49
|
show 4 more comments
I want to add one condition also, that is to filter date. The TDate Column has date as well as time. What if i want count of date 20/11/17, what to do about time entries (like 02:28, see TDate column) suffixing with the date entry ?
– Mohit Kumar
Nov 20 '18 at 21:20
include date in group by if that is also same itll make a group for stationto on same date.
– Himanshu Ahuja
Nov 20 '18 at 21:25
how to do that ?
– Mohit Kumar
Nov 20 '18 at 21:36
check my answer first query again i have edited
– Himanshu Ahuja
Nov 20 '18 at 21:40
Grouping is working. But what if i only want count of rows. The TDate has date and time both, how to search for that ? I have tried LIKE function using TDate LIKE '%20/11/2018%', but failed.
– Mohit Kumar
Nov 20 '18 at 21:49
I want to add one condition also, that is to filter date. The TDate Column has date as well as time. What if i want count of date 20/11/17, what to do about time entries (like 02:28, see TDate column) suffixing with the date entry ?
– Mohit Kumar
Nov 20 '18 at 21:20
I want to add one condition also, that is to filter date. The TDate Column has date as well as time. What if i want count of date 20/11/17, what to do about time entries (like 02:28, see TDate column) suffixing with the date entry ?
– Mohit Kumar
Nov 20 '18 at 21:20
include date in group by if that is also same itll make a group for stationto on same date.
– Himanshu Ahuja
Nov 20 '18 at 21:25
include date in group by if that is also same itll make a group for stationto on same date.
– Himanshu Ahuja
Nov 20 '18 at 21:25
how to do that ?
– Mohit Kumar
Nov 20 '18 at 21:36
how to do that ?
– Mohit Kumar
Nov 20 '18 at 21:36
check my answer first query again i have edited
– Himanshu Ahuja
Nov 20 '18 at 21:40
check my answer first query again i have edited
– Himanshu Ahuja
Nov 20 '18 at 21:40
Grouping is working. But what if i only want count of rows. The TDate has date and time both, how to search for that ? I have tried LIKE function using TDate LIKE '%20/11/2018%', but failed.
– Mohit Kumar
Nov 20 '18 at 21:49
Grouping is working. But what if i only want count of rows. The TDate has date and time both, how to search for that ? I have tried LIKE function using TDate LIKE '%20/11/2018%', but failed.
– Mohit Kumar
Nov 20 '18 at 21:49
|
show 4 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399939%2fsql-find-numbers-of-rows-in-a-table-according-to-criteria%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Hint :
select StationTo, count(*) ... group by StationTo
– Barbaros Özhan
Nov 20 '18 at 19:13
1
Possible duplicate of SQL: How to get the count of each distinct value in a column?
– JNevill
Nov 20 '18 at 19:14
@BarbarosÖzhan Inserting StationTo data should give me number of rows only.
– Mohit Kumar
Nov 20 '18 at 19:22
@JNevill Same as above
– Mohit Kumar
Nov 20 '18 at 19:22
1
select count(*) from tablename where StationTo = 'P11004400000'
– jarlh
Nov 20 '18 at 19:29