Let's say I have a database table that looks like this:
ID name salary start_date city region
----------- ---------- ----------- ----------------------- ---------- ------
1 Jason 40420 1994-02-01 00:00:00.000 New York W
2 Robert 14420 1995-01-02 00:00:00.0...
Can I have one query to check if an entry is in a mysql table, and if it is present, return a column, but if it's not present, insert it and return a value? I have a users table with the following layout:
userID - int, auto-increment
userName - varchar(100)
active - tinyint(1)
I want to do something like
select userID from users wh...
Hello. Customer has shortcuts in their data where they have a quantity of records in a field. When I parse them, I need to manufacture records, one for each quantity, incrementing the "identifier" by 7 days (because the number represents a date.Example: a single product that is on sale for four weeks and I need four records, one product...
Anyone have any SQL-fu (can be MySQL-specific) that will give me the indexes of set bits in an int, without using a procedure? How about with a procedure?
For example, given:
create table example (val int);
insert into example values (1), (2), (3), (4), (256);
I can see the set bits:
select conv(val, 10, 2) from example;
+---------...
I have a system that will allow users to send messages to thier clients. I want to limit the user to x amount of messages per day/week/month (depending on subscription). What is a good way to tally for the time period and reset the tally once the time period restarts? I would like to incorporate some sort of SQL job to reset the tally. ...
I have a program (flex) that queries a database and gets back a dataset (value, timestamp). In the program I then put each value in the set through an algorithm to get a new value resulting in all the values being transformed. Instead of having to do this transformation of data in my program I would like mysql to do it and send the res...
Building a relatively simple website, and need to store some data in the database (mainly authentication, but there's some per-user stuff). I've worked on a couple of websites previously, and used database there too, but never liked the way I accessed the database.
The way I usually did this was by having a SqlMethods.cs, which basicall...
Hi
I was trying to display just the hours in 24hr format like:
select
to_char(trunc(sysdate+(1/24)),'HH24:mi') from dual
But this only always returns 00:00. How can I show 01:00 to 23:00?
Thanks and Regards
...
Consider the models:
class Author(models.Model):
name = models.CharField(max_length=200, unique=True)
class Book(models.Model):
pub_date = models.DateTimeField()
author = models.ForeignKey(Author)
Now suppose I want to order all the books by, say, their pub_date. I would use order_by('pub_date'). But what if I want a list of all a...
The query remains constant, but the offset varies.
SELECT NAME from tbl WHERE alphabet_index='A' limit 880,1;
SELECT NAME from tbl WHERE alphabet_index='A' limit 1760,1;
SELECT NAME from tbl WHERE alphabet_index='A' limit 2640,1;
....
SELECT NAME from tbl WHERE alphabet_index='A' limit 34320,1;
Is there a better way to do this withou...
Hi,
Im using sqllite in my palm-pre web os application,
i have the table with the following structure.
Spending(id,note,amount,date,recurringtype,type,isprocessed);
the value for the recurring type will be like daily,weekly monthly etc.(1,2,3..etc)
i need to replicate a record by checking the date and the recurring type.
Can it be ac...
I am developing a site that will save data into an SQL database that describes events. One of the events being stored in the database has several variations. Some of these variations are fairly uncommon and i am trying to limit the number of blank fields in the records. I am debating between these two styles:
option A:
report_primar...
I just ran into a SQL query with about 5 different columns in the ORDER statement, is it a good practice and how does it play with performance?
...
Hi Guys, In order to see all of the tables in our companies DB I have to go find the main sys account. Is there a way to default my connection so that it shows the other users tables?
...
hello, i am looking for an SQL query, that selects exactly rows ordered by date from a table. for this there is a column that contains a timestamp.
and here comes the tricky part:
it should not select rows that are older than a certain time, but it should still select at least X rows.
so if in the given time there are not more than X ...
I have following data in my table.
I want to extract ProductId which has this criteria,
FieldValue = 1.0 and FieldValue = 'Y' and FieldValue = 'N'
This is not possible using following query
select * from MyTable
WHERE (FieldId = 50 AND (FieldValue BETWEEN '1.0' AND '1.0'))
AND (FieldId = 55 AND FieldValue = 'Y')
AND (FieldId = ...
Looking at the combination of MapReduce and HBase from a data-flow perspective, my problem seems to fit. I have a large set of documents which I want to Map, Combine and Reduce. My previous SQL implementation was to split the task into batch operations, cumulatively storing what would be the result of the Map into table and then performi...
Hello StackOverflow Community,
I had a quick question on how to exclude data from an SQL database using an SQL statement. My situation is I have a user login to their profile page where they will be able to friend people. I want to display all users except themselves that are found in the SQL database.
Thanks for all the answers!
Roha...
One of my stored procedure has long execution time (average around 4 to 7 minutes).
Now I trying to tweak it an make it run faster.
I am looking at execution plan and two things I see that using most of percentage.
First is 68% of "Clustered Index Scan" of one main tables for reporting, This table has primary key of two columns and 200...
Hi !
I'm looking for opinions on the following localization technique:
We start with 2 tables:
tblProducts : ProductID, Name,Description,SomeAttribute
tblProductsLocalization : ProductID,Language,Name,Description
and a table-valued function:
CREATE FUNCTION [dbo].[LocalizedProducts](@locale nvarchar(50))
RETURNS TABLE
AS (SELECT a.P...