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.
Related
Hello I am fairly new to the world of relational databases and SQLite, but I am in the process of trying to edit and combine multiple datasets in SQLite in R Markdown, and I was wondering if there is any way to make each change permanent. For example, in my first select statement here
SELECT id, avg(days) Average
FROM data1
GROUP BY id
And then after I have the column of averages, I would like to join one column from another dataset using the primary key like below:
SELECT data1.*, data2.purchases
FROM data1
LEFT JOIN data2
ON data1.id=data2.id
But I want the changes from the first set to be permanent and applied when I try to alter the table further. Is there something that I am doing wrong? This is all in the SQLite insert in R markdown, so could my syntax also be causing this. Any help is appreciated.
You can rename the result from the first selection an alias, i.e. A and then join it with another table data2. Usually you don't want to save the selection you made to data base, which will mess up your data base very quickly:
Nested Selection:
SELECT A.*, data2.purchases
FROM
(
SELECT id, avg(days) Average
FROM data1
GROUP BY id
) A
LEFT JOIN data2
ON A.id = data2.id
You can create a temporary table though, which is valid for your current connection to the data base:
Create A Temporary table:
CREATE TEMP TABLE A AS
SELECT id, avg(days) Average
FROM data1
GROUP BY id
Then you can use it as:
SELECT A.*, data2.purchases
FROM A
LEFT JOIN data2
ON A.id=data2.id
Normally, you will not be able to create a permanent table in the data base unless you are the maintainer of the data base and have the permission to do so.
My Col_1 looks like this-
1/20/2015 11:12:00.000000
1/21/2015 13:00:00.000000
... and so on.
I want to do (row 2 -row 1) and display the result as 1572 minutes.
Also, can someone tell me how to simply change the format of this cell to
mm/dd/yy hh:mm:ss
and get rid of all the decimals?
This should get you thinking in the right direction. The ORDER BY of the window function may need to be another column on your table if you don't want the window ordered by the actual column you are trying to do the time arithmetic. If you can share more details about the table or take a stab at the SQL yourself, we might be able to arrive at a better solution.
SELECT (MIN(Col_1)
OVER(PARTITION BY 1 ORDER BY Col_1
ROWS BETWEEN 1 FOLLOWING AND 1 FOLLOWING) -
Col_1) MINUTE(4) AS MinutesElapsed
FROM MyTable;
Using the raw data you have given as a sample:
SELECT (TIMESTAMP '2015-01-21 13:00:00.00000' -
TIMESTAMP '2015-01-20 11:12:00.00000') MINUTE(4) AS MinutesElapsed;
As for the decimals:
SELECT CAST(Col_1 AS TIMESTAMP(0)) AS NewTimeStamp;
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'
My stored procedure returns a result set like this.
I am using a Matrix Control in a RDLC Report. So the report looks like this.
You can see the month is not staring from Jan in the report. I would like to display the Columns as in the order of JAN,FEB,MAR.....etc. Can any one help me out with this?
Set Sorting in the Grouping and Sorting Properties to sort by this expression:
=iif(Fields!DataSetField.Value = "ColumnName", "zzz", Fields!DataSetField.Value)
Where "zzz" could be a number or whatever you need it to be to help the sort and then select Direction as either Ascending or Descending base on this expression.
you could modify your stored procedure to also resulting month as 1 - 12
or maybe add a calculated column that result 1 iif months == "jan" and so on...
Then you can specified sort by (the new integer type column) at column grouping.
Another way is directly set the sort by, using multiple iif:
=iif(Fields!Months.Value="JAN",1,(iif(Fields!Months.Value="FEB",2,([and so on..])))
Right click on the Tablix header and select Tablix Properties...
Click on Sorting
Click on Add and enter the folowing formula:
=Month(Fields!Month.Value & " 01 2014")
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