473,395 Members | 1,530 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,395 software developers and data experts.

nested query

ddtpmyra
333 100+
How should I do this...
First I wanted to count the students who enrolled but I wanted also to count on the same query how many are new enrollees. I cannot add the New or Old condition at the bottom because I dont want my result to be resticted. So I added a select in between and put the condition just to count how many are New enrollees. I hope I explain this clearly.

Expand|Select|Wrap|Line Numbers
  1. SELECT [Sch ID],
  2.        count ([Student ID]),
  3.        [Enrolled Date],
  4.        count ([Student ID]),
  5.        count (select [New or Old] from rawdata where [new or old]='old')) as NEW
  6. FROM tblData
  7. GROUP BY 
  8.        [Sch ID],
  9.        count ([Student ID]),
  10.        [Enrolled Date],
  11.        count ([Student ID]),
  12.        NEW
  13.  
Mar 16 '11 #1

✓ answered by deepuv04

Expand|Select|Wrap|Line Numbers
  1. SELECT [Sch ID], 
  2.        count ([Student ID]), 
  3.        [Enrolled Date], 
  4.        count ([Student ID]), 
  5.        count (CASE WHEN [new or old]='old' THEN 1 ELSE NULL END) as NEW 
  6. FROM tblData 
  7. GROUP BY  
  8.     [Sch ID], 
  9.     [Enrolled Date] 

1 1479
deepuv04
227 Expert 100+
Expand|Select|Wrap|Line Numbers
  1. SELECT [Sch ID], 
  2.        count ([Student ID]), 
  3.        [Enrolled Date], 
  4.        count ([Student ID]), 
  5.        count (CASE WHEN [new or old]='old' THEN 1 ELSE NULL END) as NEW 
  6. FROM tblData 
  7. GROUP BY  
  8.     [Sch ID], 
  9.     [Enrolled Date] 
Mar 26 '11 #2

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

Similar topics

8
by: Polar | last post by:
I am having troubles finding the parse error in this script. I've been checking for weeks. I am too new to the subject I guess. I am trying to show a readord and them have a form at the bottom...
7
by: K. Crothers | last post by:
I administer a mechanical engineering database. I need to build a query which uses the results from a subquery as its input or criterion. I am attempting to find all of the component parts of...
9
by: deko | last post by:
I need to create a Recordset of all records that appear in one table but do NOT appear in another. To get the records that appear in BOTH tables, I can do this: SELECT tblEntity.Entity_ID...
6
by: Leonardo Santos-Macias | last post by:
I would like to query a nested query string go.aspx?redirect=to.aspx?par1=value1&par2=value2 The problem is that inside go.aspx, Request.QueryString("redirect") only gives me ...
6
by: John | last post by:
Hi I have the following query; SELECT Clients.ID, Clients.Company, Clients. FROM Clients WHERE Clients. Not In (SELECT FROM ) When I do not use the keyword Not it works but not with...
0
by: wadesharp | last post by:
I would like to write a query to return nested data. The data has a master, child relationshiop and teh child is linked to the master record through the 3 column (LinkedKey). The reason this is all...
3
by: nannu | last post by:
Hi, i am using the following query string query = "SELECT *"+ "FROM DataSet"+ "WHERE Param_ID =(Select Data1 from testcases where TestCaseID='TC001') DataAdapter da=new DataAdapter();...
7
by: Kelii | last post by:
Well, I've been searching around the groups for an answer to this one, and none of the suggestions seems to be working for me. I'm almost positive that this is a simple fix, but for the life of me...
3
by: kpfunf | last post by:
I have the following two queries setup and working just fine. However, I know this is not the best way to write them, as this should be just one query, but I do not know how to nest these. The...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.