+ 1

Explain this...table name is Employee

Empid name 1 A 2 B Select *,sum(empid) from Employee; What will be the output and explain how? The output I got is 1 A 3

4th Nov 2019, 9:35 AM
C Lover
8 Antworten
+ 3
Did you get only one row in result set? I see the table contains two rows. Never seen a * followed by column selection before TBH. SUM() function returns the sum of `Empid` column, I think SUM() would return 3 instead of 2, since the `Empid` value was 1 and 2. COUNT() function however, will return 2 as it is counting rather than summing.
4th Nov 2019, 11:19 AM
Ipang
+ 1
Ipang I want all records with count how to achieve this
4th Nov 2019, 1:46 PM
C Lover
+ 1
Ipang help me
4th Nov 2019, 1:54 PM
C Lover
+ 1
Ipang I just want to display all records and it's counts in a query
4th Nov 2019, 2:07 PM
C Lover
+ 1
IMO this depends on what you are doing with the result set. if it's going back to a program, you can easily count the results in the program code, there's probably a function in the database library your code uses that will do it for you. otherwise I don't understand why you want the count of the records on each result. if you are imagining you can get a result set that has all the found results and then an additional result that just contains sum(empid), I don't think you can do that. I would agree with Ipang and say you need 2 queries.
5th Nov 2019, 6:41 PM
Nathan Stanley
Nathan Stanley - avatar
+ 1
Hello you can use group by name so it will give you all records with empid sum. Or you can use count if you want to count of records. Select name,sum(empid) from Employee Group by name
6th Nov 2019, 2:28 AM
Kaustubh Chaudhari
Kaustubh Chaudhari - avatar
0
C Lover Can you tell me what you want to do with this table? I think there's no point in repeating a SUM or COUNT with selection for all records. Perhaps separate into two queries? one for selecting all records, and another just to count the records. But I'm confused about the need to sum or count the `Empid` column. Usually SUM or COUNT is used with a condition (WHERE clause) we don't usually use those functions with primary key column (such as `Empid`). This is why I hesitate to suggest something.
4th Nov 2019, 2:03 PM
Ipang
0
C Lover I guess separate queries is the option. Select all records and then select SUM or COUNT. I don't think it's good idea mixing the results of all records with result of SUM or COUNT. You can wait for others to give a second opinion, but IMHO it's better to separate the queries.
4th Nov 2019, 2:14 PM
Ipang