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

Subquery

Just wondering if anyone can help out with this query.
I have the results of the two queries combined the way I want them, just want to tally them up so I don't have duplicate entries.

I've done this so far.
I'm trying to wrap this within one more query to add up the total column per SyteDesc.



SELECT C.SyteDesc, Sum(1) AS Total
FROM [SELECT T.SyteDesc
FROM
(SELECT DISTINCT SyteDesc
FROM SpecLog GROUP BY SyteDesc) AS T
GROUP BY T.SyteDesc]. AS T2 INNER JOIN SpecLognew AS C ON T2.SyteDesc = C.SyteDesc
GROUP BY C.SyteDesc;

UNION SELECT C.SyteDesc, Sum(-1) AS Total
FROM [SELECT T.SyteDesc
FROM
(SELECT DISTINCT SyteDesc
FROM SpecLognew GROUP BY SyteDesc) AS T
GROUP BY T.SyteDesc]. AS T2 INNER JOIN SpecLog AS C ON T2.SyteDesc = C.SyteDesc
GROUP BY C.SyteDesc;


This is an example of the output, that now I'm trying to combine and simplify.
You will have to image this in a table, but the number at the right hand side is a quantity.

SyteDesc Total
" 1 1/2"" CL1500 RF XXS FLG WN SA105N" -2
" 1 1/2"" CL1500 RF XXS FLG WN SA105N" 1
" 1 1/2"" CL2500 RTJ XXS FLG WN SA105N" -6
" 1 1/2"" CL2500 RTJ XXS FLG WN SA105N" 3
" 1 1/2"" CL900 RF XXS FLG WN SA105N" -1
" 1 1/2"" CL900 RF XXS FLG WN SA105N" 3
" 1 1/2""x1"" CL900 RF FLG SO RED SA105N" -1
" 1 1/2""x1"" CL900 RF FLG SO RED SA105N" 1
" 1 1/2""x1/4"" CL2500 R23 GASKET OVAL RING SOFT IRON" -6
" 1 1/2""x1/4"" CL2500 R23 GASKET OVAL RING SOFT IRON" 4
" 1 1/2""x1/8"" CL1500 GASKET FLEXICARB TYPE CG 316SS" -2
" 1 1/2""x1/8"" CL1500 GASKET FLEXICARB TYPE CG 316SS" 1
" 1 1/2""x1/8"" CL900 GASKET FLEXICARB TYPE CG 316SS" -1
" 1 1/2""x1/8"" CL900 GASKET FLEXICARB TYPE CG 316SS" 3
" 1 1/2""x10 1/2"" BOLT STUD SA193B7M" -4
" 1 1/2""x10 1/2"" BOLT STUD SA193B7M" 4
" 1 1/2""x3/4"" CL2500 RTJ FLG SO RED SA105N" -3
" 1 1/2""x3/4"" CL2500 RTJ FLG SO RED SA105N" 3
" 1 1/8""x6 3/4"" BOLT STUD SA193B7M" -1
" 1 1/8""x6 3/4"" BOLT STUD SA193B7M" 1
" 1 1/8""x7 3/4"" BOLT STUD SA193B7M" -5
" 1 1/8""x7 3/4"" BOLT STUD SA193B7M" 5
" 1 1/8""x7"" BOLT STUD SA193B7M" -6
" 1 1/8""x7"" BOLT STUD SA193B7M" 4
Sep 27 '07 #1
1 1591
Found the answer to my problem.
Create another query that pulls the information from my query.

My only question now, is to understand the temp tables that I believe this is creating...
C.Whatever.. T. T2.
Sep 28 '07 #2

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

Similar topics

2
by: lev | last post by:
CREATE TABLE . ( NULL , , (44) ) ID is non-unique. I want to select all IDs where the last entry for that ID is of type 11.
7
by: Andrew Mayo | last post by:
Here's a really weird one for any SQL Server gurus out there... We have observed (SQL Server 2000) scenarios where a stored procedure which (a) begins a transaction (b) inserts some rows into...
0
by: Greg Stark | last post by:
Postgresql 7.4b2 (approximately, compiled out of CVS) When I have a subquery that has a complex subquery as one of the result columns, and then that result column is used multiple times in the...
8
by: Venkata C | last post by:
Hi! Does anyone here know of a way to goad DB2 into converting a correlated subquery to a non-correlated one? Does DB2 ever do such a conversion? We have a query of the form SELECT .. FROM A...
8
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
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...
5
by: Rod | last post by:
I have a client site where the code below has been working happily for at least four months. The site is using SQL Server 7. The code is ASP.NET Last week an error appeared related to the...
22
by: Kevin Murphy | last post by:
I'm using PG 7.4.3 on Mac OS X. I am disappointed with the performance of queries like 'select foo from bar where baz in (subquery)', or updates like 'update bar set foo = 2 where baz in...
5
by: Anne | last post by:
Hello! Here is the statement in question: --STATEMENT A SELECT * FROM dbo.myTable WHERE colX in (SELECT colX FROM dbo.sourceTable) The problem with Statement A is that 'colX' does not exist...
1
by: jcf378 | last post by:
Hi all-- Does anyone have any insight as to how I might create a search form that allows a user to select criteria based on any related table in the whole database. The search form I have now only...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: 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
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...

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.