Ask a Question related to ASP Database, Design and Development.
-
Alan #1
Newbie about grouping query
In my mdb, the data is as below :
ProductID Qty Name Month CID
------------------------------------------------------------------------
Product A 2 Harddisk July A-Company
Product A 5 Harddisk July A-Company
Product A 1 Harddisk June A-Company
Product B 3 cd-rom July A-Company
Product B 2 cd-rom July B-Company
Product B 2 cd-rom June B-Company
When I select "A-Company" and "July" from listbox and submit,
I hope the result should return like this :
A-Company. July
ProductID Qty Name
--------------------------------------
Product A 7 Harddisk (Grouped, the qty will sum up
automatically)
Product B 3 cd-rom
First, I need to select the records of A-Company in July :
SQL = "Select * From Invoice where month = " & Month
SQL = SQL & " And CID ='" & CID & "'"
Then grouping the ProductID and sum the qty, also need to display the name :
SQL = "Select ProductID , Sum(Qty) As DDD , First(Name) As EEE From
Invoice GROUP BY ProductID "
Then use the script below :
ProductID Name Qty
----------------------------------------------------------------------------
----------
While not rs.eof
<%=rs("ProductID")%> <%=rs("EEE")%> <%=rs("DDD")%>
It sound perfect, is it possible to merge two query together ?
How to do that ? Thks for everyone who help me out.
Alan Guest
-
Query results - grouping
I am sure there is an easy answer to this, but I am stumped! I have a query pulling in these fields: Area, Heading, Year, IndustryGroup (Year and... -
Help with grouping and sum in query
My query looks like: <cfquery name="getTotals" datasource="db"> SELECT SUM(Extension) AS TotalDayBilling, DatePart(dw, TimesheetDate) AS... -
query/grouping question
I have a database from which I'm trying to output both a count and a grouped list of items. For example, from the following mock table I would want... -
Newbie SQL Grouping Problem
Hi All I know you're going to ask for table definitions and insert statements, but I think I'm just confused on the syntax of how to get this... -
Grouping Query Results
"John Smith" <3rtwemte001@sneakemail.com> wrote in message news:1p5khvc1kd5qatngsm6mfvvcq0ehn763va@4ax.com... Well im not sure what you want. ... -
Aaron [SQL Server MVP] #2
Re: Newbie about grouping query
SELECT ProductID, SUM(Qty), Name FROM tablename
WHERE Month='July' AND CID='A-Company'
GROUP BY ProductID, Name
ORDER BY ProductID
--
[url]http://www.aspfaq.com/[/url]
(Reverse address to reply.)
"Alan" <alan@neind.net> wrote in message
news:er83it1bEHA.3596@tk2msftngp13.phx.gbl...:> In my mdb, the data is as below :
>
> ProductID Qty Name Month CID
> ------------------------------------------------------------------------
> Product A 2 Harddisk July A-Company
> Product A 5 Harddisk July A-Company
> Product A 1 Harddisk June A-Company
> Product B 3 cd-rom July A-Company
> Product B 2 cd-rom July B-Company
> Product B 2 cd-rom June B-Company
>
> When I select "A-Company" and "July" from listbox and submit,
> I hope the result should return like this :
>
> A-Company. July
> ProductID Qty Name
> --------------------------------------
> Product A 7 Harddisk (Grouped, the qty will sum up
> automatically)
> Product B 3 cd-rom
>
> First, I need to select the records of A-Company in July :
>
> SQL = "Select * From Invoice where month = " & Month
> SQL = SQL & " And CID ='" & CID & "'"
>
> Then grouping the ProductID and sum the qty, also need to display the name-->
> SQL = "Select ProductID , Sum(Qty) As DDD , First(Name) As EEE From
> Invoice GROUP BY ProductID "
>
> Then use the script below :
>
> ProductID Name Qty
> --------------------------------------------------------------------------> ----------
> While not rs.eof
> <%=rs("ProductID")%> <%=rs("EEE")%> <%=rs("DDD")%>
>
> It sound perfect, is it possible to merge two query together ?
> How to do that ? Thks for everyone who help me out.
>
>
Aaron [SQL Server MVP] Guest



Reply With Quote

