473,387 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

give me the sql statement

hi how to i get the details following from employee table

total no of employee in each department and also total no male and female.
that is department name: total no of male: total no Female: Total Employee
Dec 3 '07 #1
2 958
Jim Doherty
897 Expert 512MB
hi how to i get the details following from employee table

total no of employee in each department and also total no male and female.
that is department name: total no of male: total no Female: Total Employee
Assuming you have a table called Employee with fields Department,Gender, EmpNo

Paste this into query analyser run it and it will create the view (I say this because the graphical view window doesnt support the case statement but the SQL is valid and the view will be created

The output will be a matrix subtotalling each gender and having subtotals for each department and a grandtotal at the bottom of the stack

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. CREATE VIEW vw_Employees_Dept AS
  4. select case when (grouping(department) = 1)
  5. then 'grand total' else isnull(department, 'unknown') end as Department,
  6. case when (grouping(gender) = 1) 
  7. then 'Subtotal '+department else isnull(gender, 'unknown') end as Gender,
  8. count(empno) as Total
  9. from Employee
  10. group by department, gender with rollup
  11. GO
  12.  
  13.  
Regards

Jim :)
Dec 8 '07 #2
amitpatel66
2,367 Expert 2GB
hi how to i get the details following from employee table

total no of employee in each department and also total no male and female.
that is department name: total no of male: total no Female: Total Employee
Could you please post your Employee table structure here for reference?
Dec 8 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Az Tech | last post by:
Hi people, (Sorry for the somewhat long post). I request some of the people on this group who have good experience using object-orientation in the field, to please give some good ideas for...
9
by: David Helgason | last post by:
I'm calling one stored procedure with a prepared statement on the server with 6 arrays of around 1200 elements each as parameters. The parameters are around 220K in total. This is taking a...
20
by: lovecreatesbeauty | last post by:
Hello experts, Is the following code snippet legal? If it is, how can exit() do the keyword return a favor and give a return value to the main function? Can a function call (or only this...
28
by: Yuri CHUANG | last post by:
"No newline at the end of your output" is really a problem? I've never learned that before. So I desire to know some tips about writting a program perfectly.Can anyone give me some tips which are...
1
by: krishna2006 | last post by:
i am beginner and i am currently learing c and can u please help my explaing the meaning how it will execute of the following statement printf ("%d\n",'-'-'-'-'/'/'/'); as the number of hi phens...
3
by: jaishu | last post by:
Hi, Do i have to give a commit statement when i update tables in backend(insert, delete,update) from a form, say when user clicks submit, it takes the data in fields and inserts it into the table...
1
by: kitskaps | last post by:
Hey, I am working on a project in VB.NET.right now i am stuckupw ith a problem, i have different pages with different forms on it , but all the entries are supposed to be entered into a single...
2
by: talkaboutquality | last post by:
Need to define a macro as, say, #ifdef NEED_FUNCTION foo(x) #else #endif
4
by: leks2608 | last post by:
Write a program in ‘C’, to find the vowels (a,e,i,o,u) in the input sentence. Constraints : 1. Input should be given by the user. 2. The output should be printed line by line as follows ...
5
by: sivadhanekula | last post by:
Hi everyone.. I want to insert a combobox with the list of test names of a database, but the testname contains 15000+ data, and I cant type all the data. so can any one help me in writing an SQL...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.