|
Been away from SQL for a while nad having trouble with this query for a report I'm trying to generate started out with this that works: code:
does not work - returns one row code:
|
# ? May 9, 2011 21:04 |
|
|
# ? May 19, 2024 19:09 |
|
geeves posted:Been away from SQL for a while nad having trouble with this query for a report I'm trying to generate code:
|
# ? May 9, 2011 21:46 |
|
How good is indexing performance (specifically for MSSQL, but in general works too) for number ranges? For example, if I did "where number BETWEEN 1 AND 1000000", does the index really help in that case, or only if it's a simple equals?
|
# ? May 9, 2011 22:05 |
|
Jethro posted:You want a GROUP BY. In this case, I'd say you want to have a subquery and do the group by in there. Thanks Jethro! - had something close to that earlier, but didn't have the GROUP BY in the query
|
# ? May 9, 2011 22:07 |
|
Golbez posted:How good is indexing performance (specifically for MSSQL, but in general works too) for number ranges? For example, if I did "where number BETWEEN 1 AND 1000000", does the index really help in that case, or only if it's a simple equals? The query planner might opt not use the index if it decides that it needs to get some other information from the table anyway, or might decide to use it .
|
# ? May 9, 2011 23:21 |
|
Golbez posted:How good is indexing performance (specifically for MSSQL, but in general works too) for number ranges? For example, if I did "where number BETWEEN 1 AND 1000000", does the index really help in that case, or only if it's a simple equals? I don't know for sure whether it'll be used in practice, that depends on the specific database you're working with, but at least the index type shouldn't be stopping it from helping. Hash indexes can only support equals queries, while btree indexes can support queries with number ranges or comparison operators in general, and afaik MSSQL only uses btree indexes.
|
# ? May 10, 2011 07:28 |
|
mySQL Replication question. Is there a good way to do this on a database by database basis? Let's say we have 10 databases on a server. We replicate now to a single slave and it works fine. The whole idea is so that we can do testing on live data, and not actually do it on the production server. The problem is, if we end up writing to the data, we get out of sync and have to dump it and start over from scratch. Not a huge deal because it's ~130mb gzipped. But it would be easier to just drop one database and bring it back online from a dump, instead of all of them. Otherwise we're just running a script to do the job in the middle of the night. The other guys want something where we can literally hit 'stop replicating', then do whatever, then hit 'start replicating' and have it magically fix itself. We're using 5.0 with statement-based replication. Has anyone used maatkit? http://www.maatkit.org/doc/mk-table-sync.html Bob Morales fucked around with this message at 16:05 on May 10, 2011 |
# ? May 10, 2011 15:53 |
|
This is on SQL Server 2008. I'm optimizing a query and want to test the performance of several different indexes. The issue is that the table is loaded into cache after the first run increasing the speed by 50x. I found some methods of clearing the system cache for benchmarking, but I'm not the only one on the server and don't want to cause slowdowns for others just so I can get a better benchmark. Without being able to test on a server by myself, what are my best options left?
|
# ? May 10, 2011 17:06 |
|
How about copying the table into a test database and fooling around with that? Your license allows you to run as many databases as you want on one server, right? Or does clearing the cache affect the whole server and not just the context of a single database?
|
# ? May 10, 2011 17:45 |
If I have a query such as:code:
edit: durr this works right? SELECT IF(val1 > 0 AND val2 = 0, 100, (val1-val2)/val2) FROM table fletcher fucked around with this message at 19:35 on May 10, 2011 |
|
# ? May 10, 2011 19:33 |
|
fletcher posted:If I have a query such as: http://www.4guysfromrolla.com/webtech/102704-1.shtml
|
# ? May 10, 2011 19:36 |
|
fletcher posted:If I have a query such as: Would SELECT COALESCE(((val1-val2) / val2), "x") work? Though that only checks for the divide-by-zero, it doesn't check that val1 is positive.
|
# ? May 10, 2011 19:36 |
|
fletcher posted:If I have a query such as: SELECT CASE WHEN val > 0 THEN (val1-val2)/val2 ELSE x END AS valColumn FROM table;
|
# ? May 10, 2011 20:53 |
|
Is it possible to combine LEFT JOIN and comma syntax for joins in MySQL? For example, instead of doing... SELECT * FROM foo LEFT JOIN bar ON foo.id = bar.id LEFT JOIN shazbot ON foo.shaz = shazbot.shaz or doing... SELECT * FROM foo, bar, shazbot WHERE foo.id = bar.id AND foo.shaz = shazbot.shaz ... is it possible to do this? SELECT * FROM (foo LEFT JOIN bar ON foo.id = bar.id) AS fnord, shazbot WHERE shazbot.shaz = fnord.shaz or something similar?
|
# ? May 10, 2011 22:39 |
|
Golbez posted:Is it possible to combine LEFT JOIN and comma syntax for joins in MySQL? For example, instead of doing... Have you tried it? Based on this page (paragraph starting with "Previously, the comma operator...") it looks like they treat a comma inside the FROM clause as meaning the same thing as JOIN, so based on that my guess would be yes you can do that. Personal opinion: Better to always use explicit join syntax.
|
# ? May 10, 2011 23:04 |
|
Golbez posted:Is it possible to combine LEFT JOIN and comma syntax for joins in MySQL? For example, instead of doing... Kinda but then its called a SubSelect and you have to specificy each field its not really a good way to select things. Select foo.f1, foo.f2, (select bar.f1, bar.f2 from bar where foo.id = bar.id) from foo I belive the second one is possible. And there is another way you can do them Select * from foo Left join bar left join shaz where bar.id = foo.id and shaz.id = bar.id
|
# ? May 11, 2011 01:08 |
|
Aredna posted:This is on SQL Server 2008. I'm optimizing a query and want to test the performance of several different indexes. The issue is that the table is loaded into cache after the first run increasing the speed by 50x. local server? Obviously it won't be exactly the same but you might be able to get a general idea.
|
# ? May 11, 2011 01:42 |
|
Hammerite posted:Have you tried it? Nope, was at home and it struck me as a possible solution to a query builder I'm making. Sprawl posted:And there is another way you can do them
|
# ? May 11, 2011 13:28 |
|
I have a production database whose tables contents I need dumped nightly to a second corporate data warehouse. For various reasons, we cannot use the typical replication methods of snapshots, log shipping or replication so we have decided to use SSIS packages and T-SQL to do the job. I've written the easy T-SQL that selects all new records in a specific table and inserts them into the corresponding table in the DW. However: My problem is how do I select records that have been changed in the production database to do an update against the DW table? This is a vague question, but I don't know enough about the process to know what information I should provide here.
|
# ? May 12, 2011 21:04 |
|
You probably want to use MERGE.
|
# ? May 12, 2011 21:47 |
|
I actually said fuckit and am now looking at a product called SQL Data Compare Pro. It does data comparisons between two databases and can be called via command line (helpful for scheduled tasks...)
|
# ? May 13, 2011 06:11 |
|
Agrikk posted:I actually said fuckit and am now looking at a product called SQL Data Compare Pro. It does data comparisons between two databases and can be called via command line (helpful for scheduled tasks...) Visual Studio Team Data Edition does it. I mean if you guys are interested spending money... But yeah - from the last guy's point. It sounds like you could probably just use MERGE and an Agent Job. Probably doesn't even need SSIS.
|
# ? May 13, 2011 17:10 |
|
I have a problem and a potential solution, but I'm not sure how I can complete the solution. I have a list of Patients with a count of their medications on a given day, as seen below: code:
code:
code:
Is it possible to do an UPDATE to add a "Visit_Number" as proposed above? Google hasn't helped me Perhaps a FUNCTION needs to be written, but I wouldn't really know where to begin on that. (data used above is not real) edit: code:
Rick Rickshaw fucked around with this message at 21:03 on May 13, 2011 |
# ? May 13, 2011 18:24 |
|
Rick Rickshaw posted:Is it possible to do an UPDATE to add a "Visit_Number" as proposed above? Google hasn't helped me Perhaps a FUNCTION needs to be written, but I wouldn't really know where to begin on that. code:
I'd advise against changing the table at all--you don't need to, and that's a great reason not to. In fact, when running reports, consider the data read-only. If you absolutely, positively need to store data, make a temporary table, but don't change anything during reports, unless it's rptInfo.lastRunDate.
|
# ? May 13, 2011 20:58 |
|
wellwhoopdedooo posted:
Thank you so much. That's incredible. It worked as-is in MySQL. You're certainly right about changing the data - I'd prefer not to, but I'm actually running MySQL off of a WAMP installation on my laptop. I'm importing the data from a spreadsheet that's dumped out of a database that I don't even have access to (consultants). It's very sketchy. So adding a column wasn't exactly a huge worry for me. But this is definitely a much better solution.
|
# ? May 13, 2011 21:22 |
|
Trying to optimize a script that takes a bunch of MySQL MyISAM databases and consolidates them for easy searching... unfortunately, I can't find anywhere to optimize it. My only thought is perhaps, do we need to ANALYZE TABLE right after recreating? This is the basic flow: CREATE TABLE LIKE ... ALTER TABLE DISABLE KEYS INSERT INTO ... SELECT ... ALTER TABLE ENABLE KEYS ANALYZE TABLE I'm guessing the analyze here is useful since we just added a few million rows to the index?
|
# ? May 17, 2011 14:55 |
|
Golbez posted:Trying to optimize a script that takes a bunch of MySQL MyISAM databases and consolidates them for easy searching... unfortunately, I can't find anywhere to optimize it. My only thought is perhaps, do we need to ANALYZE TABLE right after recreating? This is the basic flow: What do you mean take a bunch of mysql isam database and consolidates them? are all the table names the same? You would get much faster load times if you use the database export/import functions but that requires access to a shell/command prompt/.net or some other local scripting language.
|
# ? May 17, 2011 17:47 |
|
Sprawl posted:What do you mean take a bunch of mysql isam database and consolidates them? are all the table names the same? Sprawl posted:You would get much faster load times if you use the database export/import functions but that requires access to a shell/command prompt/.net or some other local scripting language.
|
# ? May 17, 2011 17:56 |
|
Golbez posted:Yeah, we have a half dozen identical (in structure) databases, vestiges of multiple mergers and acquisitions, and they have to stay separate - except when we merge them all together for searching joy. (And even that is purely experimental at this point) The mysqldump function. It would need a large amount of swtiches to get it just right like, no table creates, the --compact one, and there are some to even do it directly to another mysql server if the instances are separate.
|
# ? May 17, 2011 18:17 |
|
Okay SQL megathread. I have not read the entire thread and the first post isn't much of a Megathread info post, so I am sorry if this question has been asked before. We have some front-office / back-office software that is used for a lot of financial reporting and that sort of thing to the higher ups who run the company. The problem is, my boss is the only "DBA" and he does everything by hand. Every time they need some numbers he types of an SQL query or uses an old query and edits it. There has to be some piece of software out there that will help him build reports that are essentially templates, or are easy enough for the end-user to find the data they need with dropdown boxes, etc. Something like Crystal Reports, I guess? I do not have much experience in this department. Please recommend me something because it sucks having a boss who is supposed to be managing things and spends his entire day reinventing the wheel. Thank you! [Edit: MSSQL 2008 if it matters.]
|
# ? May 20, 2011 21:16 |
|
Crystal Reports would work fine yes and its reasonably priced if you get the "dev" edition.
|
# ? May 20, 2011 21:53 |
|
Internet Explorer posted:Okay SQL megathread. I have not read the entire thread and the first post isn't much of a Megathread info post, so I am sorry if this question has been asked before. We have some front-office / back-office software that is used for a lot of financial reporting and that sort of thing to the higher ups who run the company. The problem is, my boss is the only "DBA" and he does everything by hand. Every time they need some numbers he types of an SQL query or uses an old query and edits it. There has to be some piece of software out there that will help him build reports that are essentially templates, or are easy enough for the end-user to find the data they need with dropdown boxes, etc. Something like Crystal Reports, I guess? I do not have much experience in this department. Please recommend me something because it sucks having a boss who is supposed to be managing things and spends his entire day reinventing the wheel. Thank you! I don't really see anything wrong with what your boss is doing in theory. Sounds like he just sucks at SQL.
|
# ? May 20, 2011 21:56 |
|
Internet Explorer posted:Okay SQL megathread. I have not read the entire thread and the first post isn't much of a Megathread info post, so I am sorry if this question has been asked before. We have some front-office / back-office software that is used for a lot of financial reporting and that sort of thing to the higher ups who run the company. The problem is, my boss is the only "DBA" and he does everything by hand. Every time they need some numbers he types of an SQL query or uses an old query and edits it. There has to be some piece of software out there that will help him build reports that are essentially templates, or are easy enough for the end-user to find the data they need with dropdown boxes, etc. Something like Crystal Reports, I guess? I do not have much experience in this department. Please recommend me something because it sucks having a boss who is supposed to be managing things and spends his entire day reinventing the wheel. Thank you! We had a similar situation so we all took an afternoon and wrote a Windows Forms interface for canned reports. It's not very hard, but if you don't already have a web service/data access layer set up there's a bit more work involved.
|
# ? May 20, 2011 22:37 |
|
benisntfunny posted:I don't really see anything wrong with what your boss is doing in theory. Sounds like he just sucks at SQL. Basically this. You only need Crystal Reports (or similar - you could look into SQL Server Reporting Services, also) if you need the ability to generate 'pretty' reports for people that get scared by Excel. Your boss will probably continue to suck at reports, but at least they'll be prettier if you get CR or SSRS.
|
# ? May 21, 2011 08:56 |
|
Thel posted:Basically this. You only need Crystal Reports (or similar - you could look into SQL Server Reporting Services, also) if you need the ability to generate 'pretty' reports for people that get scared by Excel. Crystal reports also needs licensed upgrades to keep with the times, which aren't cheap. We disintegrated a crystal reports 7 installation with a bunch of reports and migrated into our proprietary reporting system just last year.
|
# ? May 21, 2011 14:25 |
|
Thel posted:Basically this. You only need Crystal Reports (or similar - you could look into SQL Server Reporting Services, also) if you need the ability to generate 'pretty' reports for people that get scared by Excel. Thanks for the feedback. Basically trying to figure out a way for the end users to get what they need without having to rely on my boss for every little thing. And yeah, these are people scared of Excel, so as pretty as as "easy" as we can make it would be for the best.
|
# ? May 21, 2011 20:45 |
|
This is on SQL Server 2008. I received a performance tip to change my queries from the form of "select ... into #temp" to "insert into #temp select ..." because the latter uses fewer locking resources. I've searched around and found one website that agrees, but all other websites say that "select ... into #temp" will be faster due to less logging taking place. The obvious answer is to test both on my system, but as a rule of thumb which method does everyone else use? What "locking resources" are being used less and how does that impact overall performance?
|
# ? May 23, 2011 23:08 |
|
Aredna posted:This is on SQL Server 2008. I received a performance tip to change my queries from the form of "select ... into #temp" to "insert into #temp select ..." because the latter uses fewer locking resources. On SQL Server I've always used INSERT INTO #PandaBear SELECT... on Oracle I do the opposite. Reasoning? None. I also prefer using variables for my temp tables in SQL Server* (i.e. @PandaBear instead). *Unless it's a metric gently caress ton of data then I'd probably stick with a temp table. benisntfunny fucked around with this message at 00:19 on May 24, 2011 |
# ? May 24, 2011 00:17 |
|
I'm a huge newbie to SQL and SQL Server, I did a short course on basic SQL queries and database structure a year ago, and remember most of it, but some things just weren't covered. Do stored procedures allow you to have if syntax? Specifically I'm trying to do something like this: Create Procedure getTable AS @tname nvarchar(10) IF @tname = 'foo' ( Begin Select * From Foo End ) ELSE IF @tname = 'bar' ( Begin Select * From Bar End ) Any help with the syntax of the thing would be nice. I'd test it right now but I'm not at my own computer at this moment.
|
# ? May 24, 2011 06:44 |
|
|
# ? May 19, 2024 19:09 |
|
bewilderment posted:I'm a huge newbie to SQL and SQL Server, I did a short course on basic SQL queries and database structure a year ago, and remember most of it, but some things just weren't covered. I recommend that you read a good introduction to database concepts and SQL before attempting to write code. What you posted isn't a syntactical issue at all -- it shows that you don't understand the fundamental concepts of relational databases. Learn those first, then look at examples of good SQL code.
|
# ? May 24, 2011 07:12 |