How To Group/list Top 3 Of Each Category W/o Using Union?

Jul 20, 2005

Hello,

So my table contains say 100,000 records, and I need to group the
categories in fld1 by the highest count of subcategories. Say fld1
contains categories A, B, C, D, E.

All of these categories contain subcategories AA, AB, AC, AD,...AJ, BA,
BB...BJ, CA, CB, CC...CJ, etc in fld2.

I am counting how many subcategories are listed for each category. Like
A may contain 5 of AA, 7 of AB, 3 of AC, 11 of AD...1 for the rest and
20 of AJ. B may contain 2 of BA, 11 of BB, 7 of BC, and 1 for the rest.
I want to pick up the top 3 subcategory counts for each category. Would
look like this:

Cat SubCat Count
A AJ 20
A AD 11
A AB 7
B BB 11
B BC 7
B BA 2

So event though each category contains 10 subcategories, I only want to
list the top 3 categories with the highest counts as above. If I just
do a group by and sort I can get this:

Cat SubCat Count
A ... ...
A
A
A
A
A
A
...
B ... ...
B
B
B
B
B
...

But I just want the top 3 of each category. The only way I can think of
to do this is to query each category individually and Select Top 3, and
then Union these guys into one query. The problem is that I have to
hardcode each category in the Union query. There may be new categoris
that I miss. Is there a way to achieve what I want without using Union?

Thanks,
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

View 3 Replies


ADVERTISEMENT

Top 3 For Every Category With Group By

Mar 6, 2006

hi.

I have a table to store salesman's performance..

as you can see at structure.jpg, Tom sold total 18 Processors (5 different modals) and sold 11 mainboards (4 different modals)

I want to report that
what are the TOP 3 Processor and Mainboard modals that Tom sold with the same query

I tried different group by methods. also subqueries.
I could't do

you see the results I need at result.jpg

View 1 Replies View Related

Sum Hours By Category And Then Group By Week Of

Jul 25, 2013

I need to sum the attendance hours by category and then group by 'Week of'. The 'Week of' start date is defined by the Monday in that week but Sunday is works too. If the Category Values are in ’Art’ or ‘PE’, they need to be combined into Non Educational. I also need to be able to flag the day(s) a student reaches 120 hours.

My table which is structured like this:

CREATE TABLE Attendance (
DOP_ID int,
Category varchar(20),
Title varchar(20),
Date datetime,
Hours int,
)

[Code] ....

I need an end result which looks like this:

ID Category Week of Total Hours
4504498 GED Program 7/1/2012 26
4504498 GED Program 7/8/2012 23
4504498 High School 7/1/2012 19
4504498 High School 7/8/2012 28
9201052 Non Educational 7/15/2012 30

ID Day_120_Hours_Reached
356485 6/30/2012
356485 11/15/2012
555666 10/12/2012
555666 2/25/2013

I have been looking for examples of a Week function that will pull out the 'week of' from a date using MS Sql Server and I can't find much info.

View 6 Replies View Related

Chart X-axis - Define HH:MM For A Group Category?

Oct 8, 2007

I have a chart that I am grouping data by Year, Month, day then Hour (this is to view server performance data) - however i need the label for the hour grouping to be in the format of HH:MM and not H:M by using expression



=HOUR(Fields!Timestamp_perfmon.Value) &":"&MINUTE(Fields!Timestamp_perfmon.Value)



...but this as you would kind of expect returns 0-23:0-5 ie 18:1 whereas i need it to return 18:12 or 8:12 PM..



when i change the format code for the x-axis it unfortunatey screws up all my other group by values and labels..



can anyone help? Please....

View 2 Replies View Related

Reporting Services - Chart X-axis - Define HH:MM For A Group Category?

Oct 5, 2007



I have a chart that I am grouping data by Year, Month, day then Hour (this is to view server performance data) - however i need the label for the hour grouping to be in the format of HH:MM and not H:M by using expression

=HOUR(Fields!Timestamp_perfmon.Value) &":"&MINUTE(Fields!Timestamp_perfmon.Value)

...but this as you would kind of expect returns 0-23:0-5 ie 18:1 whereas i need it to return 18:12 or 8:12 PM..

when i change the format code for the x-axis it unfortunatey screws up all my other group by values and labels..

can anyone help?

View 2 Replies View Related

SQL Server 2012 :: Obtaining A Comma Delimited List For Each Group In The Output Of A Group By Query?

Jan 10, 2014

I'd like to ask how you would get the OUTPUT below from the TABLE below:

TABLE:
id category
1 A
2 C
3 A
4 A
5 B
6 C
7 B

OUTPUT:

category count id's
A 3 1,3,4
B 2 5,7
C 2 2,6

The code would go something like:

Select category, count(*), .... as id's
from TABLE
group by category

I just need to find that .... part.

View 3 Replies View Related

Category/Parent Category Design And Querying

Jun 29, 2005

Hi,

I have a simple table:

Categories
----------
CategoryID
ParentID
Name

I want to associate my Products to a category so that I can search by category....ok.  If I just have a simlpe table:

CategoryProducts
-------------------
CategoryId
ProductId

I can link a product to a category.  Now, if I just link a product to a single category, such as the bottom leaf category:

Self Help / Personal Development / Spiritual / Meditation

I would link a product to the Meditation category.  However if I
click on Self Help while browsing, I want to see all items underneath
Personal Development, Spiritual and Meditiation.  So my question
is is this a good way to store the product-category relationships, or
should I put many entries into CategoryProducts to keep the queries
simlpe and faster? Are they faster doing it this way? In this way there
would be 4 entries for a product in meditation.  My personal idea
is that adding all entries up a tree arm of a category path will be
cumbersome to manage, but it does solve the problem of clicking on Self
Help and seeing all products that exist within sub-categories.  I
am sure an SQL query would be able to work this out, but I dont know if
performance would be something to consider on an ecommerce site? Are
there any patterns fo rthis stuff - seems a reasonably repeatable
pattern for business sites?

Thanks,

jr.

View 5 Replies View Related

Need To Union And Group Split Databases

Jun 10, 2008

We had a divestiture within our company. Now what used to be contained in one database in now split into two databases. One showing all history and one being all current data as of 6/1/2008. Is there an easy way to Union or Join these? Right now I'm currently doing a simple UNION ALL, but can't group the two select statements:

SELECT
Year,Location,QtySold
FROM
historydb

UNION ALL

SELECT
Year,Location,QtySold
FROM
currentdb

Can't do a subset and group both of these selects. How would some of you pro's do this? Right now I can put this in a simple view and then create a SP off of this view that would do this grouping, but it seems like I should be able to do it all in one query. Thanks.

View 2 Replies View Related

Using Group By Clause In Union Query

Sep 19, 2007

Hi all,

I have two table having datas like

Table1
--------------------------------------------------------------------
A C1 C2 C3 C4
--------------------------------------------------------------------
x 0 0 3 2
x 0 1 0 2
x 0 0 2 1
y 1 5 2 0


Table2
--------------------------------------------------------------------
A C1 C2 C3 C4
--------------------------------------------------------------------
x 0 0 1 4
y 1 0 3 1
y 1 2 0 0
y 0 0 5 1

select * from(
select A,C1,C2,C3,C4 from Table1 group by A
union
select A,C1,C2,C3,C4 from Table2 group by A
)as t

Result:
--------------------------------------------------------------------
A C1 C2 C3 C4
--------------------------------------------------------------------
x 0 1 5 5
y 1 5 2 0
x 0 0 1 4
y 2 2 8 2

But i need the result like i.e grouped by column 'A'
--------------------------------------------------------------------
A C1 C2 C3 C4
--------------------------------------------------------------------
x 0 1 6 9
y 3 7 10 2

select * from(
select A,C1,C2,C3,C4 from Table1 group by A
union
select A,C1,C2,C3,C4 from Table2 group by A
)as t group by A

The above query gives the following error
[Error Code: 8120, SQL State: S1000] Column 't.C1' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

Please help me out.

-Anand

View 3 Replies View Related

Reporting Services :: Using GROUP BY With UNION ALL

May 15, 2015

Here is my sql code. I'm using a "union all" to merge Incidents and Service Requests into one table.  This works fine when I don't use the "group by".  When using "group by" to get the total number of tickets per "Area" it is giving me duplicates.  So it is returning a distinct list of "Area" from both select statements. 

SELECT
IRAreaDN.DisplayNameas 'Area'
,Count(IR.Id) as 'Total Requests'
--,IRSupportGroupDN.DisplayNameas 'Support Group'
--, CAST(DATEADD(MI,DATEDIFF(mi,GETUTCDATE(),GETDATE()),IR.CreatedDate) AS DATE)as 'Created Date'
--, CreatedByUser.UserName as 'Created By User ID'

[Code] ....

View 2 Replies View Related

UNION With GROUP BY 'Invalid Column Name'

Mar 9, 2008


I have a query similar to the following, but it gives the following error:
'Invalid column name 'GroupName'.'


SELECT 'Primary' as GroupName, City

FROM PrimaryTable

UNION ALL

SELECT SpecialGroupName AS GroupName, City

FROM Table2

GROUP BY GroupName, City


GroupName is varchar(30)

Any ideas why this would fail. Thanks in advance.

Terry


View 6 Replies View Related

Group / Union Statement - Pull Unique Records From A Large Table

Sep 22, 2014

I am trying to use SQL to pull unique records from a large table. The table consists of people with in and out dates. Some people have duplicate entries with the same IN and OUT dates, others have duplicate IN dates but sometimes are missing an OUT date, and some don’t have an IN date but have an OUT date.

What I need to do is pull a report of all Unique Names with Unique IN and OUT dates (and not pull duplicate IN and OUT dates based on the Name).

I have tried 2 statements:

#1:
SELECT DISTINCT tblTable1.Name, tblTable1.INDate
FROM tblTable1
WHERE (((tblTable1.Priority)="high") AND ((tblTable1.ReportDate)>#12/27/2013#))
GROUP BY tblTable1.Name, tblTable1.INDate
ORDER BY tblTable1.Name;

#2:
SELECT DISTINCT tblTable1.Name, tblTable1.INDate
FROM tblTable1
WHERE (((tblTable1.Priority)="high") AND ((tblTable1.ReportDate)>#12/27/2013#))
UNION SELECT DISTINCT tblTable1.Name, tblTable1.INDate
FROM tblTable1
WHERE (((tblTable1.Priority)="high") AND ((tblTable1.ReportDate)>#12/27/2013#));

Both of these work great… until I the OUT date. Once it starts to pull the outdate, it also pulls all those who have a duplicate IN date but the OUT date is missing.

Example:

NameINOUT
John Smith1/1/20141/2/2014
John Smith1/1/2014(blank)

I am very new to SQL and I am pretty sure I am missing something very simple… Is there a statement that can filter to ensure no duplicates appear on the query?

View 1 Replies View Related

Concatenate List Of Values Under A Group

Aug 4, 2007

I have the following dataset:

State ZIP Homes Schools
WA 98007 2000 4
WA 98052 3000 5
WA 98079 2000 3

Now if I have set the group by expression on State but as display if I want to show it as €œ[98007, 98052, 98079]€? how can I accomplish this.

My report needs to show:
State Homes Schools
[98007, 98052, 98079] 7000 12


Any help will be greatly appreciated

View 6 Replies View Related

Exporting From SQL To An Outlook Group Or Dist List?

Jul 20, 2005

I need to export a list of name and email address fields from a SQLtable, in some format so that a user can take the file I generate andImport it into Outlook and it will keep all the names together in aGroup or Distribution List rather than dumping them into the user'smain address book. Any ideas?Francesco

View 1 Replies View Related

SELECT With GROUP BY And Build A List From Vales Not Shown

Apr 16, 2004

Hard to write a subject line to describe this one.

Anayway, I have a table with names and address plus an extra field noting a part number of product.

I'd like to build a SELECT string that will return one result for each name/address (uniques only in other words) and build a comma delimited field of all the part numbers for that name/address.

Example:

NAME ADDRESS PART NUMBER
John Smith 555 Main st., los angeles, ca 90003 5000
John Smith 555 Main st., los angeles, ca 90003 6650
Mike Jones 8569 West 18th Ave., San Diego, ca 1255
John Smith 555 Main st., los angeles, ca 90003 5144
Mike Jones 8569 West 18th Ave., San Diego, ca 2399


So I'd like my results to look like this:

NAME ADDRESS PARTS
John Smith 555 Main st., los angeles, ca 90003 5000,6650,5144
Mike Jones 8569 West 18th Ave., San Diego, ca 1255,2399

THanks in advance for any suggestions!

Raul

View 2 Replies View Related

Problem With Group By When Using Case Statements In The Select List.

Oct 11, 2007



I am using SQL Server 2005 and fairly new at using SQL Server. I am having problems using a Case statements in the select list while have a group by line. The SQL will parse successfully but when I try to execute the statement I get the following error twice :

Column 'dbo.REDEMPTIONHISTORY.QUANTITY' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.



Below is the my sql statement:

SELECT dbo.DateOnly(TH.TransactionDate) AS RptDate, RH.Item,

ItemRef =

Case

when RH.Quantity < 0 then Sum(RH.Quantity)

when RH.Quantity >= 0 then Sum(0)

end

FROM dbo.RHISTORY AS RH INNER JOIN
dbo.TRANSHISTORY AS TH ON RH.TRANSACTIONID = TH.TransactionID

WHERE (dbo.DateOnly(TH.TransactionDate) BETWEEN '10-1-2007' AND '10-5-2007')
AND (RH.TransactionCode IN (13, 14, 15, 16))

Group by dbo.DateOnly(TH.TransactionDate), RH.Item

The TransHistory table contains, primary key transactionid, TransactionDate and the RHistory contains all the details about the transaction, the RHistory table is joined to the TransHistory table by foreign key TransactionID. I am trying to get totals for same item on the same day.

Any help will be greatly appreciated. I am also having trouble using If..Then statements in a select list and can not fin the correct syntax to use for that.

View 12 Replies View Related

GROUP BY Expressions Must Refer To Column Names That Appear In The Select List.

Jan 19, 2008

Hi,

Is there any way to group variables present in a select statement.

My code:

SELECT @var1=something, @var2=something_else
FROM ...
GROUP BY @var1

I wanted to group by 'something' hence I used a variable to assign it to. But I'm unable to group it.

Any thoughts?

Thanks,
Subha





View 1 Replies View Related

Looping Through Stored Procedure Inside Another Stored Procedure And Displaying The Category And Then Displaying 1 Item In Each Category

Sep 21, 2006

I used to do this with classic asp but I'm not sure how to do it with .net.Basically I would take a table of Categories, Then I would loop through those.  Within each loop I would call another stored procedure to get each item in that Category. I'll try to explain, Lets say category 2 has a player Reggie Bush and a player Drew Brees, and category 5 has Michael Vick, but the other categories have no items.Just for an example.. Category Table: ID   Category1      Saints2      Falcons3      Bucaneers4      Chargers5      FalconsPlayer Table:ID    CategoryID   Player                 News                                Player Last Updated1            1           Reggie Bush       Poetry in motion                                9/21/20062            1           Drew Brees         What shoulder injury?                        9/18/20063            5           Michael Vick       Break a leg, seriously.                       9/20/2006 Basically I would need to display on a page:SaintsReggie BushPoetry in MotionFalconsMichael VickBreak a leg, seriously.So that the Drew Brees update doesnt display, only the Reggie Bush one, which is the latest.I have my stored procedures put together to do this.  I just don't know how to loop through and display it on a page.  Right now I have two datareaders in the code behind but ideally something like this, I would think the code  would go on the page itself, around the html.

View 1 Replies View Related

Integration Services :: Insert To Data From SSIS Package To SharePoint List People Or Group Column

Dec 13, 2013

When I am trying to insert to data from SQL ssis package to SharePoint list people or group column I am getting below error.[SSIS.Pipeline] Error: SSIS Error Code DTS_E_PROCESSINPUTFAILED.  The ProcessInput method on component "SharePoint List Destination" (25) failed with error code 0x80131500 while processing input "Component Input" (34). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running.

View 8 Replies View Related

T-SQL (SS2K8) :: Using Union ALL Or Union Kills Performance On Stored Proc

Jun 12, 2014

SQL Server 2008 r2...

I have a query which does 3 selects and Union ALLs each to get a final result set. The performance is unacceptable - takes around a minute to run. If I remove the Union All so that the result sets are returned individually it returns all 3 from the query in around 6 seconds (acceptable performance).

Any way to join the result sets together without using Union All.

Each result set has exactly the same structure returned...

Query below [for reference]...

WITH cte AS (
SELECT A.[PoleID], ISNULL(B.[IsSpanClear], 0) AS [IsSpanClear], B.[SurveyDate], ROW_NUMBER() OVER (PARTITION BY A.[PoleID] ORDER BY B.[SurveyDate] DESC) rownum
FROM[UT_Pole] A
LEFT OUTER JOIN [UT_Surveyed_Pole] B ON A.[PoleID] = B.[PoleID]

[Code] .....

View 4 Replies View Related

How Does Union/union All Work Inside SQL Server?

Apr 29, 2008



Why the sequence different?



select * from (

select id=3,[name]='Z'

union all select 1,'G'

union all select 2,'R'

union all select 4,'Z'

) as t

order by [name]

--result:

---------

--1 G

--2 R

--4 Z

--3 Z

select * from (

select id=3,[name]='Z'

union select 1,'G'

union all select 2,'R'

union all select 4,'Z'

) as t

order by [name]

--result:

----------

--1 G

--2 R

--3 Z--changed

--4 Z

View 3 Replies View Related

Reporting Services :: Display Group Name Value Of Each Group In Column Header Outside The Group?

Sep 29, 2015

I have an SSRS 2012 table report with groups; each group is broken ie. one group for one page, and there are multiple groups in multiple pages.

'GroupName' column has multiple values - X,Y,Z,......

I need to group 'GroupName' with X,Y,Z,..... ie value X in page 1,value Y in page 2, value Z in page 3...

Now, I need to display another column (ABC) in this table report (outside the group column 'GroupName'); this outside column itself is another column header (not a group header) in the table (report) and it derives its name partly from the 'GroupName'  values:

Example:

Value X for GroupName in page 1 will mean, in page 1, column Name of ABC column must be ABC-X Value Y for GroupName in page 2 will mean, in page 2, column Name of ABC column must be ABC-Y Value Z for GroupName in page 3 will mean, in page 3, column Name of
ABC column must be ABC-Z

ie the column name of ABC (Clm ABC)  must be dynamic as per the GroupName values (X,Y,Z....)

Page1:

GroupName                 Clm ABC-X

X

Page2:

GroupName                 Clm ABC-Y

Y

Page3:

GroupName                 Clm ABC-Z

Z

I have been able to use First(ReportItems!GroupName.Value) in the Page Header to get GroupNames displayed in each page; I get X in page 1, Y in page 2, Z in page 3.....

However, when I use ReportItems (that refers to a group name) in the Report Body outside the group,

I get the following error:

Report item expressions can only refer to other report items within the same grouping scope or a containing grouping scope

I need to get the X, Y, Z ... in each page for the column ABC.

I have been able to use this - First(Fields!GroupName.Value); however, I get ABC-X, ABC-X, ABC-X in each of the pages for the ABC column, instead of ABC-X in page 1, ABC-Y in page 2, ABC-Z in page 3, ...

View 4 Replies View Related

TOP N Value Per Category

Oct 26, 2006

HelloI am using sql server 2005.I have two tables as described below.Table1UserID UserSales---------------------1 102 133 174 195 216 107 128 119 3110 2311 2412 1013 16Table2UserID Country----------------------1 Canada2 Canada3 Canada4 Canada5 Canada6 USA7 USA8 USA9 USA10 USA11 UK12 UK13 UKI want to get top 2 UserSales for each country and remaining should bedisplayed as Total as Others for that country.Can someone please help me with this query?RegardsAmit

View 1 Replies View Related

Breakdown By Category

Dec 22, 2005

Let's say you a 1000 records in the Employees table, who are spread over 40 different cities.
How would you get a breakdown of how many employees in each city ?

Do I have to loop with  a  Count(*)   for each CityID, or something ?

There must be a more straightforward method.

View 1 Replies View Related

HAVING (COUNT(category) &> 1) , Not Only 1 Row

Sep 25, 2006

i am using this code :

SELECT MAX(user) AS lastuser, category
FROM journal
GROUP BY category
HAVING (COUNT(category) > 1)

it works but returns 1 line by category >1

i need all the user (all the rows) HAVING (COUNT(category) > 1) , not only 1

if 1 category has only 1 user i must not keep it


i am not shure to be clear :-)

thank you for helping

View 8 Replies View Related

Category Tables

Feb 25, 2004

What are the thoughts on using a categoy table? What I mean by this is to have a table used to hold simply a category identifier for other table(s).

Eg:

Hardware Table
Hadware (PK) | Category (FK) | Description | Finish | etc....
------------------------------------------------------------------------------
P1 | Plate | 4"x4"x1/4 plate | Painted |

HardwareCategories
Category (PK)
-----------------
Plate
Channel
Angle


Should this be done or simply provide a category field in the hardware table? I like the extra table because it kind of ensures that a user doens't add a plate with a category value "Plate", another user adds "plate", and another user adds "Plates", etc....

What are your thoughts if any?

Mike B

View 1 Replies View Related

Update Sys Category

Jan 27, 2008

I'm trying to remove a read only/stand by database that I believe was a messed-up attempt at log shipping. When I go through the interface it says 'cannot remove database because it is set up for replication'. If I try and 'directly update' the sys tables (yea I know you can't do that anymore) I get the error:


Msg 259, Level 16, State 1, Line 1

Ad hoc updates to system catalogs are not allowed.



So my dilema is I just want to delete a database that was attempting to do log shippinig and is now stuck in read only/standby. How can this be done in SQL 2005?

Thanks,
Phil

View 18 Replies View Related

Trying To Select Newest Row For Each Category...

Feb 6, 2004

Hi everyone -

I am building from the Time Tracker Start Kit, trying to get a better feel for how MS thinks we should do things.

In my editing, I have built a new Stored Procedure, trying to pull the newest entries for a specified person.

I have the following that will return all entries for a specific person, sorted by date, newest first:


SELECT
EntryLogID, TT_EntryLog.Description, Duration, EntryDate, TT_EntryLog.ProjectID AS ProjectID,
TT_EntryLog.CategoryID AS CategoryID, TT_Categories.Abbreviation AS CategoryName, TT_Projects.Name AS ProjectName,
ManagerUserID, TT_Categories.Abbreviation AS CatShortName
FROM
TT_EntryLog
INNER JOIN
TT_Categories
ON
TT_EntryLog.CategoryID = TT_Categories.CategoryID
INNER JOIN
TT_Projects
ON
TT_EntryLog.ProjectID = TT_Projects.ProjectID
WHERE
UserID = @UserID
ORDER BY
EntryDate Desc


This will return something like:


EntryLogId Description Duration EntryDate ProjectID CategoryID CategoryName ProjectName ManagerUserID CatShortName
14Can type date in date... .00 2004-02-04 10:28:00116Pros ITS Project Management App 3 Pros
12Changed "Entry Date"... .00 2004-02-03 13:28:00116Pros ITS Project Management App 3 Pros
13Added default button ... .00 2004-02-03 00:00:00116Pros ITS Project Management App 3 Pros
11Removed hours per p... .00 2004-02-03 00:00:00116Pros ITS Project Management App 3 Pros
6Isn't this cool .00 2004-02-02 00:00:00229Pros Knowledge Base 3 Pros
9Added week-by-week... .00 2004-02-02 00:00:00116Pros ITS Project Management App 3 Pros
10Fixed Update comma... .00 2004-02-02 00:00:00116Pros ITS Project Management App 3 Pros
1Built initial framewor... 6.00 2004-01-30 00:00:00116Pros ITS Project Management App 3 Pros
5Adding up to 8 hours... 2.00 2004-01-30 00:00:00229Pros Knowledge Base 3 Pros
3Debugged - fixed a f... 1.00 2004-01-23 00:00:00229Pros Knowledge Base 3 Pros



What I would like to accomplish is to return only the newest entry for each ProjectID (so in the above example, there would only be 2 entries, EntryID 14 and 6)

Any ideas?

Thanks in advance-

View 4 Replies View Related

Select Last Entry Per Category?

Nov 8, 2005

Hello,

I am trying to select the last entry (by date) for each category in a table.

For example, if my table had the following fields;

id, category, product, datePosted,....

...how would I select the last product for each category posted by date?

Any guidance is appreciated.

Thanks,
AC

Probably a simple solution, but can't find it my brain right now!

View 7 Replies View Related

Running Sum - How To Get It To Restart For Each Category

Jun 6, 2012

I was able to get a running some to work, but i cant seem to get it to restart for each category... for example this is what I have...

ID Name Return Run. Sum
1 aaa 0.1 0.1
2 aaa 0.2 0.3
3 aaa 0.3 0.6
4 aaa 0.1 0.7
5 bbb 0.5 1.2
6 bbb 0.4 1.6
7 bbb 0.1 1.7
8 bbb 0.3 2
9 bbb 0.2 2.2

How do i get it to start over at bbb??? Here is the code in access 2010:

Format(1000+(DSum("Return","Monthly Performance Dates","[ID]<=" & [ID] & "")*1000),"00.00")

View 1 Replies View Related

Query To Count AGE By Category

Sep 17, 2013

How to write a query to count AGE by category (Exec or non Exec)

sample are as follow:

----Age Group---------
Category: Age <25 age 25-35 age 45-50 Total
Exec 2 1 3
Non Exec 10 5 5 20

Grand total: 23

View 2 Replies View Related

10 Random Records, 1 From Each Category

Dec 1, 2006

I'm not sure if this is a completely dumb question, but please humor me:) I have a table of records, called Records, each of which has aCategory_ID that places it in a specific category; the details of thecategories are stored in another table called Category. What I need todo is retrieve a recordset that contains one record from each category,but where the records that are retrieved are random. I know how toretrieve one or more random records using "order by NewID()", but havenot been able to work out how to get one random record from eachcategory.Any assistance in this puzzler will be HUGELY appreciated!ThanksFEB

View 7 Replies View Related

Select Records Under Sub Category

Aug 30, 2007

I got 3 table below

Region
---------------
RegionID
ParentID
RegionName

Cuisine
--------
CuisineID
CuisineName

Restaurant
-----------
RetaurantID
CuisineID
RegionID

Data

RegionID RegionName ParentID
1 RN_1 Null
2 RN_2 Null
3 RN_1_1 1
4 RN_1_2 1
5 RN_2_1 2

CuisineID CuisineName
1 CU1
2 CU2

RestaurantID CuisineID RegionID
1 1 4
2 1 2
3 2 5
4 1 3


What I would like is to write a stored procedure to browse the restaurant by either regionname or cuisinename.
I tried to create the view from those three table and create the stored procedure to search from the view based on criterias
I tried to search for regionName = RN_1 & CuisineName = 2 the result is empty. It is true because there is no restaurant under that region however what I want to have is list all restaurants under that RegionName children e.g
RN_1 has RN_1_1 & RN_1_2 & RN_1_3 so the result should be displayed as

RestaurantID CuisineID RegionName ParentID
1 1 RN_1_2 1
4 2 RN_1_1 1

Could anyone help me to do so. Thank you

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved