Exclude vice-versa entries from result set using sql query [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 9 years ago.
Improve this question
Let suppose there four entries in table as shown below.I want only Row 1 and 2 in resultset.
The vice versa case of 1 and 2 in Row 3 and 4 should be excluded. Please suggest a query for that
Pk Col1 Col2 Col3 Col4
1 A B 20 30
2 E D 40 50
3 B A 20 30
4 D E 40 50

WHERE Col1 < Col2 immediately comes to mind. Actually, that would give you rows 1 and 4, but I presume that's good enough for yuor purposes.

Related

How to compute average Cost in SQL based on category? [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 months ago.
Improve this question
So let's say we have a table called phone.
and i need another column to show the average cost of a brand phone
I know i can do something like this:
SELECT brand, AVG (cost)
FROM Phone
GROUP BY brand;
and get something like this table:
Can someone help me how i would get this result below using a select sql statement?
You can use avg(cost) over (partition) such as this:
select *,
round(avg(cost) over (partition by brand), 2) as avg_cost
from phone;
phoneid
brand
cost
avg_cost
2
apple
8
10.00
6
apple
12
10.00
3
google
7
6.50
4
google
6
6.50
1
samsung
10
9.33
5
samsung
4
9.33
7
samsung
14
9.33

VB.net SQL query to Linq [closed]

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 4 years ago.
Improve this question
I want to make this Query into a Linq Query:
Select name,sum(qty) as qty from tblCars groub by name
Table:
Name | Qty
Ferrari 1
Nissan 2
Ferrari 2
Honda 3
Honda 1
Name | Qty
Ferrari 3
Nissan 2
Honda 4
I want to be able to achieve that using an array or list in VB.net and Linq.
tblCars.GroupBy(Function(x) x.Name).Select(Function(x) New With {.Name = x.Key, .Sum = x.Sum(Function(s) s.qty)})

select a single unique record in a column if records are duplicate [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
select a single unique record in a column if records are duplicate
we a class table
c_id
timing
we have records as (c_id,timing) values
1 | 3-5
2 | 5-7
3 | 3-5
4 | 7-9
5 | 9-11
6 | 11-1
7 | 7-9
we select all timing but we have 3-5 and 7-9 timing record 2 times when we select the timing it show only 1 time and other timing show like
3-5
5-7
7-9
9-11
11-1
If all you want is just the unique timing then use:
SELECT timing from class_Table group by timing
Unless there's other information you are trying to get from this query. Is there any additional info you can give us?

query for selecting distinct names and count names in sql [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
In my table 2 columns are there. Name and Marks. Something like this.
Name Marks
---------- -----------
AAA 50
BBB 48
CCC 54
AAA 52
DDD 55
BBB 60
AAA 66
I need to retrieve from the table something like below
Name No.of.attempts Max Mark
------- ---------------- ------------
AAA 3 66
BBB 2 60
CCC 1 54
DDD 1 55
You should do like:
select name,count(name) as no_of_attempts,max(marks)
from table_name
group by name
fddle demo here
you can do it like this
select name,COUNT(name) as nameCount,MAX(markes) as marks from #abc group by name

Oracle SQL grouping [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 9 years ago.
Improve this question
I am getting records as below:
PERIOD LABEL1 LABEL2 LABEL3 LABEL4
-----------------------------------
1 12
1 14
1 11
2 10
2 09
and so on..
I want it like below:
PERIOD LABEL1 LABEL2 LABEL3 LABEL4
-----------------------------------
1 12 14 11
2 10 09
Hope its clear.
If you only have positive values, you can use a mix of nvl and max:
select period,
max(nvl(label1, 0)) label1,
max(nvl(label2, 0)) label2,
max(nvl(label3, 0)) label3,
max(nvl(label4, 0)) label4
from my_table
group by period;