Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
In the application we have a query, we have a situation where we are bringing records back that are open, closed, and archived with a date associated with them. This is a table associated and joined with a main table. The table could have 1 to 3 records associated with the same ID of the main table depending if the record has been opened, closed, and/or archived. The three stages essentially of open, closed, and archived.
What we're looking to do is this: When EStatusID = 1 (Which means open) we need the DateClosed to read as blank (because it's not closed or archived yet)
SELECT
E.EID,
EStatus.EStatusID,
FORMAT (EStatus.DateCreated, 'MM/dd/yyyy') as DateClosed
I won't bore you with the rest of the query because it's long and not useful to the question. So we need some kind of Case statement or sub query or something in the Select to accomplish this task.
You can use a case expression:
CASE WHEN EStatus.EStatusID <> 1 THEN FORMAT (EStatus.DateCreated, 'MM/dd/yyyy') END
AS DateClosed,
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 11 months ago.
Improve this question
I have 2 columns called price and PID in database called seatinginfo.
Both columns will have multiple of the same values like
pid 1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3
price 10,10,30,40,60,80,70,90,90,90,90 etc
I'm looking to make a query that will give me a list of all unique prices and pick just 1 or the max connected pid.
So example I only want one price,pid like 10,1 30,1 40,1 60,2 etc
Thanks
This is probably as simple as basic aggregation. Something like this should work based on the pretty vague details.
select price
, max(pid)
from YourTable
group by price
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a column in SQL item_expired, this column stores data in the form of dates from other items. What I want to ask, how do I subtract existing date in item_expired column with the current date, which will then be stored in the remaining_time column.
I've tried the command below, but isn't working:
SELECT
item_description, item_expired,
item_date = DATEDIFF(DAY, CURRENT_TIMESTAMP, item_expired)
FROM Customers;
As GMB has mentioned in the comment above, date functions depend on the database type you are using. Assuming you are asking about MySQL the below query will provide you with the remaining time required.
select
(CURRENT_DATE - item_expired) as remaining_time
from customers;
While this will provide you with the remaining time, you will have to write a separate insert to insert the remaining time for the table column.
Query in sql server :
select DATEDIFF(day, CURRENT_TIMESTAMP,item_expired)
will give you the difference in days between the current date and the item_expired date
Provide more information about you problef for more direct answers
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to know how I can find duplicate data entries within one table in clickhouse.
I am actually investigating on a merge tree table and actually threw optimize statements at my table but that didn't do the trick. The duplicate entries still persist.
Preferred would be to have a universal strategy without referencing individual column names.
I only want to see the duplicate entries, since I am working on very large tables.
The straight forward way would be to run this query.
SELECT
*,
count() AS cnt
FROM myDB.myTable
GROUP BY *
HAVING cnt > 1
ORDER BY date ASC
If that query gets to big you can run it in pieces.
SELECT
*,
count() AS cnt
FROM myDB.myTable
WHERE (date >= '2020-08-01') AND (date < '2020-09-01')
GROUP BY *
HAVING cnt > 1
ORDER BY date ASC
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
my table Muster contain following data
And final output I want is
How to query database to get required output
Having 4 identical names is confusing, Not 100 % sure what you mean, but if you want to update the current table with opposite values, this is how to do it. Status will remain the same if it has different values.
UPDATE Muster
SET status = CASE status WHEN 'present' THEN 'absent'
WHEN 'absent' THEN 'present'
ELSE status END
Select * From Muster order by Status
hope this will help you.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want to search an table column. and select all rows that contains a string.
I do that on this way:
select * from memos where contains (article, '"test*"')
The next problem is to order the acticles on relevance. So if a record contains 4 times the word of wordpart 'test' i want it on top and if it contains 3 times the word 'test' i want it below 4. And so order it on how many times a word is in a row.
Assuming the article is stored as a varchar() or nvarchar(), then you can do this
select *
from memos
where contains (article, '"test*"')
order by len(replace(article, 'test', 'test1')) - len(article) desc;
This replaces test with a string one character longer, measures the length, and then subtracts the original length. Voila. The number of times that test occurs. This should take place only on articles that have the search term.
I'm not sure if SQL Server has something like this built-in to the full text engine.