Divide all values but one in sql table [closed] - sql

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 got this table, and i want to divide all the values on one of the columns except one.
I havent wrote any code about it just looking for an explanation on how to do it, if anyone could help out would appreciate.

In order to modify the content of one column in all rows except one, you can use the following query:
UPDATE tablename SET columName = columnName / 42 WHERE rowId !=42;
WHERE contains the condition that has to evaluate to true, in order for the update to take effect. My example modifies all rows except for those whose rowId column contains the value 42.

Related

Find distinct from multiple columns [closed]

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

How to remove repeat rows in SQL? [closed]

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
I need to remove repeated records in search result. I have 3 columns (id, worklevel & umobile).
It looks like below:
Red places is repeat but I need just one of them in result.
Try using DISTINCT
SELECT DISTINCT column1, column2, ...
FROM table_name;

Selecting columns with values ​greater than 0 [closed]

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
i have only one row with a lot columns in my table. I want to select columns with values greater than zero.
WHERE (col_1 > 0) and ... (col_99 > 0)
It will be too long query, if i want to write all statements. Does it possible to write query with selecting columns with values > 0 ?
Bro flow the method its lengthy by works.
First you unpivot the data and select values where column value > 0
secondly Pivot again and you will get you desire result.

Remove rows with duplicate value for a column in SQL [closed]

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 4 years ago.
Improve this question
From the above table, I want to remove the rows that have the duplicate CODE column. Out of the duplicate rows, the row with the smallest ID_CHECK should be retained.
Output:
If I understand correctly, this should be your SQL query:
Select Names, Code, ID_CHECK
FROM
(
Select Names, Code, ID_CHECK,
ROW_NUMBER() OVER(Partition by Name,Code Order By ID_CHECK) as rnk
FROM table
)tmp
WHERE tmp.rnk=1;
Let me know if this works.

Problems with SQL query finding three names with the most records [closed]

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
I have a table and I want to display the 3 names (Ted, Ringo, Paul) that have the most records using an SQL query.
It's a primitive question, but please help me.
my table:
SELECT TOP 3 Name
FROM YourTable
GROUP BY Name
ORDER BY COUNT(*) DESC