VB.net SQL query to Linq [closed] - sql

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)})

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

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?

Exclude vice-versa entries from result set using sql query [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
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.

DISTINCT AND COUNT [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
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
Improve this question
There is a column of Country Code and another 3 column with MEDALS GOLD,SILVER, and BRONZE
I want to Show The total of GOLD,SILVER, and BRONZE Medals they have got for each country,
Graph look like this
COUNTRY_ISOCODE PART_GOLD PART_SILVER PART_BRONZE
--------------- ---------- ----------- -----------
AUS 2 0 0
AUS 2 0 3
AUS 0 0 0
ZAF 0 0 0
ZAF 1 1 0
But i want it be like this
COUNTRY_ISOCODE PART_GOLD PART_SILVER PART_BRONZE
--------------- ---------- ----------- -----------
AUS 4 0 0
ZAF 1 1 0
Assuming you do talk about SQL (as implied by count and distinct):
select country_isocode,
sum(part_gold) as part_gold,
sum(part_silver) as part_silver,
sum(part_bronze) as part_bronze
from the_table
group by country_isocode;

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;