Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Super noob here.
I want to update column AI_Amount to 0 whenever column Delete_Field = C.
When a customer leaves the delete_field gets updated to a C but the AI_Amount field will not zero out. How do I go about doing this?
I tried using the update clause but it says I don't have permission. I don't want to update the actual table just the query results.
I don't want to update the actual table just the query results.
You seem to want select, not update:
select
delete_field,
case when delete_field = 'C' then 0 else ai_amount end as ai_amount,
-- other columns here
from mytable
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
How does one get the first name info from a Users table, which has a first name column?
First of all welcome to the community. I suggest you read the guidelines on how to properly ask a question here and you might want to write a title that is relevant to your question.
Now to the question:
Assuming tblUsers is a table in your database and 'first_name' is a column in your table, you can use SELECT followed by the column you want to select.
Lastly, add FROM to select which table you want to select from.
So in your case it would be:
SELECT first_name FROM tblUsers;
You can read more about SELECT here
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 need to add a column to a sql table that counts how many rows per ID. Some IDs may just have 1 result while others may have 3+.
What's the most efficient way to handle this?
In a query, you can use:
select t.*, count(*) over (partition by id) as cnt
from t;
This is probably the simplest method. You can wrap a view around this. You can also create a materialized view.
If you actually need a column, then you have two choices for keeping it up-to-date:
Triggers, to update the value each time a row is inserted, deleted, or updated.
A user-defined function and a computed column.
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 3 years ago.
Improve this question
Is there standard SQL syntax for causing query to fail when a query tries to delete a non-existent entity? E.g.
DELETE FROM entity WHERE id = 501;
does not fail, even when there is no entity with id = 501. Can it be done in cross-database way?
Depending on environment you can get deleted row count, where you can tread 0 as error.
Or you can have a trigger that raises an exception if no rows deleted.
Here is one way you can handle this in Oracle:
BEGIN
DELETE FROM test
WHERE id = 4;
IF (SQL%NOTFOUND) THEN
dbms_output.put_line('It is already gone');
END IF;
END;
/
Here is a small demo.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
What would the active record query be for the following SQL?
SELECT tag_id, COUNT(*) AS id FROM tags_mystories GROUP BY tag_id;
Thanks!
TagsMystory.pluck(:tag_id).group_by(:tag_id).count
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 7 years ago.
Improve this question
I have about 1000 entries in table. It's simple table with 10 columns. Query:
SELECT * FROM my_table
server runs the query, but is processing it for a long time.
P.S. I know this is not enough info, so please comment and I will add what is needed.
Got it. Not related to SQL. Server got overflown by data. Someone was spamming it.
You can try to use TOP. For example try to select 100 rows and look if server still stucks:
SELECT TOP 100 * FROM my_table