Hi All,
Not exactly a SQL programmer by a long way and I'm having a problem with a query and would like a little advice if someone would be so kind.
I have a table with various fields, of which I'm interested in two (RefNumber and Status).
The RefNumber is not unique has it can be linked to multiple users at the same time. So the data I have looks like this (for the two fields in question).
RefNumber / Status
1234 / 1
1234 / 1
1234 / 2
3333 / 1
3333 / 1
3333 / 1
5555 / 2
5555 / 1
What I'm trying to get out of the database is distinct reference numbers whose status is not at 2.
So the result I'm after int this case would be "3333".
I've tried the following query, but it doesn't seem to work.
select ReferenceNumber from CountTable c where Status<
(SELECT max(status) as Status
FROM CountTable cl
where cl.ReferenceNumber = c.referencenumber
group by referencenumber)
Any pointers greatly appreciated.Your nested query just needs to find those refnumbers that have a status of 2, and your outer query finds the rest
SELECT DISTINCT REFNUMBER
FROM COUNTTABLE
WHERE NOT REFNUMBER IN (
SELECT DISTINCT REFNUMBER
FROM COUNTTABLE
WHERE STATUS=2)|||select ReferenceNumber
from CountTable
group
by ReferenceNumber
having sum(
case when status = 2
then 937
else 0 end ) = 0|||Rudy,
I'll concede that you're much better at this than I am, so I'll assume
that your's is the better solution. My question is "Why"?
Mark|||Thanks guys - both those queries work perfectly. :beer:
I must admit, I have little more idea of what RedNeckGeek's is doing over r937's query.
I'll have a read up on the unknown (to me) functions you use.
Don't think I'll ever fully understand SQL, which is quite sad as it seems quite powerful.
I'm sure, when I do things in code to manipulate data read from a DB, I could do them in SQL with much less overhead. At the moment, I used stored procedures in SQLServer to get data, manipulate it in code then update the DB again through stored procs......I can almost hear your screams of pain from here! :eek:
Any pointers to some good idiot-proof tutorials??
Thanks again for your help.
Regards,
Mark J.|||Or still:SELECT DISTINCT RefNumber
FROM CountTable AS c
WHERE NOT EXISTS (
SELECT 1
FROM CountTable
WHERE RefNumber = c.RefNumber AND Status = 2)This might be more performant than the others (depending on the size of the table, the average number of entries per RefNumber, and the RDBMS).|||You actually seem to have a pretty good deal working already. You understand that SQL is powerful, but like any powerful tool it requires some basic knowledge of the tool and/or instruction before you can use it safely. You've got somebody managing your SQL Server that understands your limits and is providing you with stored procedures to do the "heavy lifting" on the SQL side. This is definitely not a bad place to start!
I'm not sure what kind of resources you are looking for (web sites, classes, books, etc). I'll give you a couple of my suggestions, but feel free to ask more or different questions.
First and foremost, asking questions here is likely to be a really good source of information for you. There are a bunch of crusty old pharts like me, and a few folks that actually present a professional image too. We all have opinions, and most of those opinions are pretty good, and lord knows if you ask a question you're pretty likely to get some good answers.
Don't overlook the possibility of classes at a local university, trade school, or even an Adult Education class. The hands on nature and the interaction with people is really valuable to most people in the early stages of the learning process for almost anything. The quality varies all over the map, running from astounding (in a good sense) to astounding (as in a waste of time) depending on the class, instructor, and student... While this can definitely be a "mixed bag" and can go wrong, it usually goes very, VERY right.
If you are looking for books, then I'd recommend SQL Queries for Mere Mortals (http://search.barnesandnoble.com/booksearch/isbnInquiry.asp?z=y&EAN=9780201433364&itm=1) or the Hitchhiker's Guide (http://search.barnesandnoble.com/booksearch/isbnInquiry.asp?z=y&EAN=9780321243621&itm=1) for someone using Microsoft SQL Server.
There are literally thousands of other resources. Give me a nudge in the right direction and I bet I can suggest something!
-PatP
Showing posts with label programmer. Show all posts
Showing posts with label programmer. Show all posts
Monday, March 12, 2012
Reference Material Recommendations
I'm a relatively experienced SQL Server 2000/2005 development DBA/Programmer
but I'm up for a new position involving systems that are dealing in 1000s of
user transactions a second and I don't have any experience in that area.
Does anyone have suggestions for reading I can do to familiarize myself with
the specific hot points of that type of system?
Any help is appreciated.
Thanks
RCBThese are not all 2005 specific but might be a good start:
http://www.sql-server-performance.com/sql_server_performance_audit10.asp
Performance Audit
http://www.microsoft.com/technet/prodtechnol/sql/2005/library/operations.mspx
Performance WP's
http://www.swynk.com/friends/vandenberg/perfmonitor.asp Perfmon counters
http://www.sql-server-performance.com/sql_server_performance_audit.asp
Hardware Performance CheckList
http://www.sql-server-performance.com/best_sql_server_performance_tips.asp
SQL 2000 Performance tuning tips
http://www.support.microsoft.com/?id=224587 Troubleshooting App
Performance
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_perfmon_24u1.asp
Disk Monitoring
http://sqldev.net/misc/WaitTypes.htm Wait Types
Tempdb in 2005:
http://download.microsoft.com/download/4/f/8/4f8f2dc9-a9a7-4b68-98cb-163482c95e0b/WorkingWithTempDB.doc
Physical Database Storage:
http://download.microsoft.com/download/4/f/8/4f8f2dc9-a9a7-4b68-98cb-163482c95e0b/PhysDBStor.doc
Andrew J. Kelly SQL MVP
"Robert B" <RobertB@.discussions.microsoft.com> wrote in message
news:0C9E5F9D-2F7A-4495-8CE8-018E3C358B9C@.microsoft.com...
> I'm a relatively experienced SQL Server 2000/2005 development
> DBA/Programmer
> but I'm up for a new position involving systems that are dealing in 1000s
> of
> user transactions a second and I don't have any experience in that area.
> Does anyone have suggestions for reading I can do to familiarize myself
> with
> the specific hot points of that type of system?
> Any help is appreciated.
> Thanks
> RCB|||Thanks for the list of articles, some were familiar to me some had some great
information. Does anyone else know of any articles more about the 'design'
aspects of high transaction databases?
Thanks Again
but I'm up for a new position involving systems that are dealing in 1000s of
user transactions a second and I don't have any experience in that area.
Does anyone have suggestions for reading I can do to familiarize myself with
the specific hot points of that type of system?
Any help is appreciated.
Thanks
RCBThese are not all 2005 specific but might be a good start:
http://www.sql-server-performance.com/sql_server_performance_audit10.asp
Performance Audit
http://www.microsoft.com/technet/prodtechnol/sql/2005/library/operations.mspx
Performance WP's
http://www.swynk.com/friends/vandenberg/perfmonitor.asp Perfmon counters
http://www.sql-server-performance.com/sql_server_performance_audit.asp
Hardware Performance CheckList
http://www.sql-server-performance.com/best_sql_server_performance_tips.asp
SQL 2000 Performance tuning tips
http://www.support.microsoft.com/?id=224587 Troubleshooting App
Performance
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_perfmon_24u1.asp
Disk Monitoring
http://sqldev.net/misc/WaitTypes.htm Wait Types
Tempdb in 2005:
http://download.microsoft.com/download/4/f/8/4f8f2dc9-a9a7-4b68-98cb-163482c95e0b/WorkingWithTempDB.doc
Physical Database Storage:
http://download.microsoft.com/download/4/f/8/4f8f2dc9-a9a7-4b68-98cb-163482c95e0b/PhysDBStor.doc
Andrew J. Kelly SQL MVP
"Robert B" <RobertB@.discussions.microsoft.com> wrote in message
news:0C9E5F9D-2F7A-4495-8CE8-018E3C358B9C@.microsoft.com...
> I'm a relatively experienced SQL Server 2000/2005 development
> DBA/Programmer
> but I'm up for a new position involving systems that are dealing in 1000s
> of
> user transactions a second and I don't have any experience in that area.
> Does anyone have suggestions for reading I can do to familiarize myself
> with
> the specific hot points of that type of system?
> Any help is appreciated.
> Thanks
> RCB|||Thanks for the list of articles, some were familiar to me some had some great
information. Does anyone else know of any articles more about the 'design'
aspects of high transaction databases?
Thanks Again
Labels:
database,
dba,
experienced,
involving,
material,
microsoft,
mysql,
oracle,
position,
programmer,
recommendations,
reference,
relatively,
server,
sql,
systems
Subscribe to:
Posts (Atom)