PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.sqlserver.server > Start and end row numbers of "groups"
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Start and end row numbers of "groups"

Réponse
 
LinkBack Outils de la discussion
Vieux 17/06/2008, 15h57   #1
Maury Markowitz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Start and end row numbers of "groups"

I have a large query that gets pasted into an Excel sheet. The query
sorts the results by company name and then location (traditional stock-
keeping report). The user can then change various numbers in the
sheet, writing down stock for instance, and a series of formulas
updates the numbers for that row.

Now I'm trying to add subtotaling for the two "groupings" (company,
location). Since the user can change the numbers within the groups,
the subtotals have to be formulas that update. I would like to put
these formulas in as explicit rows, like "=SUM(Q1:Q37)" instead of
using SUMIF or one these more expensive formulas. To make this easy,
it would be nice if every row of the result set also contained the
start and end position of it's own group, or alternately the number of
rows in the group.

So, is there an easy way that sql can generate these sorts of "row
numbers within a group"? I seem to recall reading about this recently,
but I can't find the key words when I'm looking now...

Maury
  Réponse avec citation
Vieux 17/06/2008, 16h31   #2
Plamen Ratchev
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Start and end row numbers of "groups"

On SQL Server 2005 you can use COUNT(*) OVER. You can partition by the
grouping columns and get count for the groups:

COUNT(*) OVER(PARTITION BY company, location)

You can also add ranking within a group using ROW_NUMBER() or
RANK()/DENSE_RANK().

HTH,

Plamen Ratchev
http://www.SQLStudio.com

  Réponse avec citation
Vieux 18/06/2008, 16h34   #3
Maury Markowitz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Start and end row numbers of "groups"

On Jun 17, 10:31am, "Plamen Ratchev" <Pla...@SQLStudio.com> wrote:
> On SQL Server 2005 you can use COUNT(*) OVER. You can partition by the
> grouping columns and get count for the groups:
>
> COUNT(*) OVER(PARTITION BY company, location)


Great, thanks! That's exactly what I was looking for.

Maury
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h44.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,07596 seconds with 11 queries