I have a table of which one column holds dates in this format '04/17/2014'.
I want to select rows of the table based on time. I'm trying to get all rows after a certain date. After reading posts here I tried the following, which doesn't seem to work. I get a lot of rows from 2013 back with this query. Can anybody help?
select Value_Date from Table_Outstanding
where VALUE_DATE > '04/12/2014'
This did it. Thanks everybody.
select * from Table_Outstanding
where strftime('%m/%d/%Y', VALUE_DATE) > '04/12/2014'
Related
I got a table like this, and i want to get the largest consecutive count of rows where win=1 for each puuid and ordered by game_creation DESC. I tried many solution of the web but can't get any of them to work, maybe somebody here can help me.
I'm using SQLite3 and trying to query for recent rows. So I'm having SQLite3 insert a unix timestamp into each row with strftime('%s','now'). My Table looks like this:
CREATE TABLE test(id INTEGER PRIMARY KEY, time);
INSERT INTO test (time) VALUES (strftime('%s','now')); --Repeated
SELECT * FROM test;
1|1516816522
2|1516816634
3|1516816646 --etc lots of rows
Now I want to query for only recent entries, for example, I'm trying to get all rows with a time within the last hour. I'm trying the following SQL query:
SELECT * FROM test WHERE time > strftime('%s','now')-60*60;
However, that always returns all rows regardless of the value in the time column. I really don't know what's going on.
Also, if I put WHERE time > strftime('%s','now') it'll return nothing (which is expected) but if I put WHERE time > strftime('%s','now')-1 then it'll return everything. I don't know why.
Here's one more example:
sqlite> SELECT , strftime('%s','now')-1 AS window FROM test WHERE time > window;
1|1516816522|1516817482
2|1516816634|1516817482
3|1516816646|1516817482
It seems that SQLite3 thinks the values in the middle column are greater than the values in the right column!?
This isn't at all what I expect. Can someone please tell me what's going on? Thanks!
The purpose of strftime() is to format values, so it returns a string.
When you try to do computations with its return value, the database must convert it into a number. And numbers and strings cannot be compared directly with each other.
You must ensure that both values in a comparison have the same data type.
The best way to do this is to store numbers in the table:
INSERT INTO test (time)
VALUES (CAST(strftime('%s','now') AS MAKE_THIS_A_NUMBER_PLEASE));
(Or just declare the column type as something with numeric affinity.)
I have one column in a table in which there's some data like this:
TBSPL/C/Mar12/634
KBSPL/C/jan14/735
TBDPL/C/aug13/834
SBSPL/C/july12/034
I need to sort the data based on the year in a GridView, but I'm getting the problem that the year is stuck in the middle of the value, for example jan14 in KBSPL/C/jan14/735. Because of this, I am not able to sort it by the year.
I tried this, but I'm not having any success:
select *
from emp
order by date
You could just do:
SELECT * FROM EMP
ORDER BY LEFT(PARSENAME(REPLACE(DATE,'/','.'),2),2)
Thanks.
I'm trying to get LINQ SQL to grab and total this data, I'm having a heck of a time trying to do it too.
Here is my code, that doesn't error out, but it doesnt total the data.
' Get Store Record Data
Dim MyStoreNumbers = (From tnumbers In db.Table_Numbers
Where tnumbers.Date > FirstOfTheMonth
Select tnumbers)
I'm trying to create a loop that will group the data by DATE and give me the totals so I can graph it.
As you can see, I'd like to set totals for Internet, TV, Phone, ect... Any help would be great, thank you!
You can group and total the numbers one by one, like this:
From tnumbers In db.Table_Numbers
Where tnumbers.Date > FirstOfTheMonth
Group by tnumbers.Date
Into TotalPhone = sum(tnumbers.Phone)
Select Date, TotalPhone
Here is a link with explanations of this subject from Microsoft.
Edit: added grouping
I have two tables, one contains a list of items which is called watch_list with some important attributes and the other is just a list of prices which is called price_history. What I would like to do is group together 10 of the lowest prices into a single column with a group_concat operation and then create a row with item attributes from watch_list along with the 10 lowest prices for each item in watch_list. First I tried joins but then I realized that the operations where happening in the wrong order so there was no way I could get the desired result with a join operation. Then I tried the obvious thing and just queried the price_history for every row in the watch_list and just glued everything together in the host environment which worked but seemed very inefficient. Now I have the following query which looks like it should work but it's not giving me the results that I want. I would like to know what is wrong with the following statement:
select w.asin,w.title,
(select group_concat(lowest_used_price) from price_history as p
where p.asin=w.asin limit 10)
as lowest_used
from watch_list as w
Basically I want the limit operation to happen before group_concat does anything but I can't think of a sql statement that will do that.
Figured it out, as somebody once said "All problems in computer science can be solved by another level of indirection." and in this case an extra select subquery did the trick:
select w.asin,w.title,
(select group_concat(lowest_used_price)
from (select lowest_used_price from price_history as p
where p.asin=w.asin limit 10)) as lowest_used
from watch_list as w