|
Super Mario Shoeshine posted:sorry for being a pest but i need some advice on how to separate a char field like "QUAKE\QUIT\JOHN" to 3 differents fields. (I am trying to separate the names field on a database by surnames and names. What flavor of SQL are you using? Many support regular expressions which will make it easy and quick to sort out. Is the delimiter actually a backslash or will it be something else (i.e. a space)?
|
# ? Jul 11, 2008 18:47 |
|
|
# ? May 11, 2024 06:53 |
|
Super Mario Shoeshine posted:sorry for being a pest but i need some advice on how to separate a char field like "QUAKE\QUIT\JOHN" to 3 differents fields. (I am trying to separate the names field on a database by surnames and names. This is for MSSQL. I know how bad this is going to look. But unfortunately, there's no split string function in TSQL. I used a temp table and this appears to work. (no guarantees): code:
|
# ? Jul 11, 2008 18:52 |
|
I have a feeling that there is a simple way to do what I need, but the answer is eluding me . Basically, I have a mySQL database with a birth date column (standard datetime field). There are a few thousand rows in my database. Most of the birth days I have in there are correct, but some are off by one hour, making the date incorrect. For example, 2/19/1984 12:00:00 AM is a correct birthdate. However, some birth dates are one hour behind, making the whole date wrong. Example: 12/31/1899 11:00:00 PM should be: 1/1/1900 12:00:00 AM. Does anyone know of a way to add one hour to the dates that have an 11:00 PM date to correct them?
|
# ? Jul 12, 2008 04:54 |
|
This might do it:code:
|
# ? Jul 12, 2008 20:42 |
|
chocojosh posted:My learning of SSIS goes from "Hmm.. this tool is pretty neat and I love the concept but they need to get the interface improved and a few bugs fixed" down to "why the hell can't I do something so basic?". I did warn you.
|
# ? Jul 13, 2008 11:53 |
|
I have no hair left to pull out... I have a table called table... code:
I need to select Names of people who have only made one color of... widgets, or whatever. code:
code:
|
# ? Jul 14, 2008 19:50 |
|
zim posted:I have no hair left to pull out... Do you expect us to do your homework? http://www.w3schools.com/sql/sql_groupby.asp
|
# ? Jul 14, 2008 19:52 |
|
its not my homework but thank you, got it
|
# ? Jul 14, 2008 19:54 |
|
Aredna posted:What flavor of SQL are you using? Many support regular expressions which will make it easy and quick to sort out. I am using MySQL and the delimiter is actually a backslash so its all crumped together and looks so terrible and oh god
|
# ? Jul 14, 2008 21:45 |
|
Super Mario Shoeshine posted:I am using MySQL and the delimiter is actually a backslash so its all crumped together and looks so terrible and oh god MySQL supports regex, but from what I can find it does not support using regexs selecting a portion of a substring. If I'm wrong I'm sure someone will jump in here with an example Otherwise, what grimace posted above will be the logic you'll want to use. The syntax will be slightly different for MySQL instead of MSSQL, but it should be close. Also, make sure you use two backslashes when you put them in the charindex so that they are escaped properly.
|
# ? Jul 14, 2008 22:40 |
|
Is a TRUNCATE, DROP faster than a DROP in SQL Server? The reason I'm guessing so is because with a drop, it would try to record everything in the transaction log. But if I truncate it first, there would be nothing to record, ergo, faster.
|
# ? Jul 15, 2008 18:57 |
|
Triple Tech posted:Is a TRUNCATE, DROP faster than a DROP in SQL Server? The reason I'm guessing so is because with a drop, it would try to record everything in the transaction log. But if I truncate it first, there would be nothing to record, ergo, faster. Never dropped a large enough table to measure, but DROP DATABASE is near instantaneous, and I'd assume internally DROP TABLE uses similar, if not mostly the same, code path as TRUNCATE. So I can't imagine doing a TRUNCATE first would be any quicker.
|
# ? Jul 15, 2008 20:32 |
|
If I run code:
Edit: Nevermind, I'm a retard. I was including a "GROUP BY" in my original query that was preventing the return from being 0.
|
# ? Jul 15, 2008 20:48 |
|
Zombywuf posted:Never dropped a large enough table to measure, but DROP DATABASE is near instantaneous, and I'd assume internally DROP TABLE uses similar, if not mostly the same, code path as TRUNCATE. So I can't imagine doing a TRUNCATE first would be any quicker. I've done them on large tables (500 million rows or more) so I know from experience.
|
# ? Jul 15, 2008 22:53 |
|
DLCinferno posted:I've done them on large tables (500 million rows or more) so I know from experience. Just curious, how many columns were in this table?
|
# ? Jul 15, 2008 23:12 |
What's the most efficient way to query a table for timestamps that are < 15 minutes old in MySQL?code:
code:
|
|
# ? Jul 15, 2008 23:27 |
|
fletcher posted:What's the most efficient way to query a table for timestamps that are < 15 minutes old in MySQL? I am willing to bet that both queries get optimized down to the same thing.
|
# ? Jul 16, 2008 01:21 |
|
fletcher posted:What's the most efficient way to query a table for timestamps that are < 15 minutes old in MySQL? In the first expression you are converting a date column from its native format into an integer for a comparison. Stick with the second expression. Although they are meant to be equivalent, the optimizer will more than likely not rewrite the first one to make them equivalent.
|
# ? Jul 16, 2008 03:04 |
|
Randomosity posted:Alright, I'm sure this is really simple, but how can I select the rows from table A that do not have associated rows in table B? We use this as an interview question. There are at least 5 available techniques, but somewhere between 50% and 75% of interviewees fail to provide even one working solution. To give this post more content, the 5 I know of are: - MINUS - NOT IN - NOT EXISTS - NOT ANY (Oracle only? Bizarre syntax that I never use) - null outer join
|
# ? Jul 16, 2008 03:46 |
|
MoNsTeR posted:We use this as an interview question. There are at least 5 available techniques, but somewhere between 50% and 75% of interviewees fail to provide even one working solution. What is a NULL outer join? I thought it would be a "LEFT OUTER JOIN" (you could use Right outer join but in practice I've only seen left). I do like the subquery answers -- a good trick would be to ask for TWO ways to do it
|
# ? Jul 16, 2008 04:51 |
|
MoNsTeR posted:We use this as an interview question. There are at least 5 available techniques, but somewhere between 50% and 75% of interviewees fail to provide even one working solution. EXCEPT instead of MINUS on non-Oracle systems For PostgreSQL (maybe others?) you can use: field <> ANY(...)
|
# ? Jul 16, 2008 05:22 |
|
chocojosh posted:What is a NULL outer join? I thought it would be a "LEFT OUTER JOIN" (you could use Right outer join but in practice I've only seen left).
|
# ? Jul 16, 2008 15:22 |
|
Triple Tech posted:Just curious, how many columns were in this table? bigint 8 char 8 nvarchar 520 datetime 8 datetime 8 datetime 8 char 1 int 4 ...table was about 230GB. Drop happened in less than a second, although now I need to shrink the database.
|
# ? Jul 16, 2008 16:35 |
|
Our instance of SQL Server 2005 (we are not technically adept/DB mastahs) had 130 columns over 4M rows, and it took over a minute to drop. So, I figured it was trying to log everything. The log is already set to simple.
|
# ? Jul 16, 2008 19:33 |
|
Jethro posted:I think he means a LEFT OUTER JOIN with WHERE RightTable.key IS NULL More or less. I would write it as: code:
|
# ? Jul 16, 2008 20:06 |
|
Triple Tech posted:Our instance of SQL Server 2005 (we are not technically adept/DB mastahs) had 130 columns over 4M rows, and it took over a minute to drop. So, I figured it was trying to log everything. The log is already set to simple.
|
# ? Jul 16, 2008 20:18 |
|
MoNsTeR posted:More or less. I would write it as: I'll line up on the other side. ANSI joins are the only thing that make large statements understandable and readable. The (+) operator makes life miserable, has limitations, and even Oracle recommends you get on with your life. 10.2 SQL Reference posted:Oracle recommends that you use the FROM clause OUTER JOIN syntax rather than the Oracle join operator. Outer join queries that use the Oracle join operator (+) are subject to the following rules and restrictions, which do not apply to the FROM clause OUTER JOIN syntax:
|
# ? Jul 16, 2008 20:20 |
|
var1ety posted:I'll line up on the other side. ANSI joins are the only thing that make large statements understandable and readable. The (+) operator makes life miserable, has limitations, and even Oracle recommends you get on with your life. I agree, I kinda like using JOIN. If I'm doing simple inner join, then I just set the relevant fields equal in the WHERE clause, but if I need anything weird and/or complicated, I'll use the full JOIN notation every time. Still, thats a pretty cool interview question.
|
# ? Jul 16, 2008 21:13 |
|
Triple Tech posted:Our instance of SQL Server 2005 (we are not technically adept/DB mastahs) had 130 columns over 4M rows, and it took over a minute to drop. So, I figured it was trying to log everything. The log is already set to simple. 130 columns
|
# ? Jul 16, 2008 21:41 |
|
Yeah, obviously if I was at the helm, there would be a lot more judicious use of what goes where, etc. But they're sort of playing a shotgun approach to the way we're modeling the data, so it just so happens that one slice of our in-house model has 130 possible dimensions. The vast majority of the fields are null, and I can scream audit until the cows come up, but that's just the way it is. The data that we're getting from other people though, 80 columns, easy. And we're still talking a few million rows, per month.
|
# ? Jul 16, 2008 22:12 |
|
I just found a way to separate that string but i need to know how to pass the result of a string function to a temp variable, i mean for example if i use this function SELECT RIGHT() i get as a result a number, is there a way to pass this number to a variable i just defined in the session?
|
# ? Jul 18, 2008 17:50 |
|
Super Mario Shoeshine posted:I just found a way to separate that string but i need to know how to pass the result of a string function to a temp variable, i mean for example if i use this function SELECT RIGHT() i get as a result a number, is there a way to pass this number to a variable i just defined in the session? SELECT @variable = RIGHT(whatever you're doing here)
|
# ? Jul 18, 2008 18:34 |
|
Do you guys have an efficient method of handling the averaging of user-submitted numerical ratings? Say I have a site with items you can rate between 1 and 10, where I want to display the aggregate average of all votes. I was thinking of having a temporary table that gets an additional row added each time a user creates a rating, and a stored procedure that gets called every hour or so to add the temp values to a permanent table, after which it flushes out the temporary one. Would this make more sense than just having a single table with columns for 'count of reviews' and 'total of review values', and updating these values directly each time a user submits a review?
|
# ? Jul 18, 2008 22:17 |
|
chemicalhero posted:Do you guys have an efficient method of handling the averaging of user-submitted numerical ratings? A table that stores a total rating and total number of users that have rated it? You'd only need to access one row for writing ratings and retrieving them.
|
# ? Jul 18, 2008 23:48 |
|
I have a FoxPro table (close enough to SQL?) that has a few rows that are flagged as deleted. Is there any way (through code) that I can either unset these deleted flags or that I can still access the data? I know by typing SET DELETED OFF and BROWSE, I can view the data in the table...but I need to be able to access deleted data from a program that I'm running. Please say there's some way to do this EDIT: I think I found a way SET DELETED OFF SELECT * FROM table WHERE DELETED()=.T. craisins fucked around with this message at 15:52 on Jul 21, 2008 |
# ? Jul 21, 2008 15:40 |
|
I have a SQLite database that I'm trying to search through, and firstly LIKE doesn't use indexing, so I'm having some really slow results. So I'm trying to move to using =>, as I'm doing a search where I just want all character that are bigger than the first part of the string - if I type Al I want it to list Alabama, and for strings in general, it seems to be using the index with =>. However, there are also some things I'd like to search that are numeric columns that it treats strictly as numeric columns. So if I search for "5" I'll get the results I want "50, 51, etc" but I'll also get 60, which isn't what I want. My query started simple, and has evolved to this mess which still doesn't do what I want: SELECT Report.NumColumn FROM Report WHERE +CAST(Report.NumColumn AS text) >=CAST(5 AS text) Anyone ever had to do something like this before?
|
# ? Jul 21, 2008 18:02 |
|
Alex The Great posted:I have a SQLite database that I'm trying to search through, and firstly LIKE doesn't use indexing, so I'm having some really slow results. If I understand you correctly you could solve your problem by also adding a substr() predicate. Something like this: code:
A poster named D. Richard Hipp posted some advice for a similar question at http://www.nabble.com/SQLite-Like-Query-Optimization-td15511886.html. D. Richard Hipp posted:LIKE operators cannot use indices unless the index is var1ety fucked around with this message at 20:43 on Jul 21, 2008 |
# ? Jul 21, 2008 18:23 |
|
I'm running an analysis on data being generated by a PLC. The database is formatted specially for some software that runs on site so it's a bit of a pain to get all the data I need. Here's the query I'm running:code:
It seems the solution should be very simple, but I'm quite new to this. Help would be much appreciated. Mr. DNA fucked around with this message at 20:10 on Jul 22, 2008 |
# ? Jul 21, 2008 18:26 |
|
Mr. DNA posted:I'm running an analysis on data being generated by a PLC. The database is formatted specially for some software that runs on site so it's a bit of a pain to get all the data I need. Here's the query I'm running: Either way, the short answer is "it may be silly, but that's pretty much the way to do it." The long answer is "stick it in a view or (RDBMS depending) a CTE or subquery."
|
# ? Jul 21, 2008 21:43 |
|
|
# ? May 11, 2024 06:53 |
|
Jethro posted:What RDBMS? Looks like either MSSQL or MySQL, but I don't know which. It's MSSQL. Thanks for your answer. Those key words look like they'll be enough for me to solve the problem with some reading. Thanks again for your help!
|
# ? Jul 22, 2008 00:12 |