Oracle SQL grouping [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
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;

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

Sort Dates in Chronological order in pandas [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 2 years ago.
Improve this question
Can anyone suggest me how to sort the dates in Pandas? I tried some methods but couldn't able to get desired result
Index Date Confirmed
0 01-01-2020 2
1 01-02-2020 3
2 01-03-2020 1834
3 02-01-2020 23
4 02-02-2020 3
5 02-03-2020 5
First convert column type to datetime using pd.to_datetime then sort using pd.DataFrame.sort_values and then reset index.
df.Date = pd.to_datetime(df.Date, dayfirst=True)
df = df.sort_values('Date').reset_index(drop=True)
df
Date Confirmed
0 2020-01-01 2
1 2020-01-02 23
2 2020-02-01 3
3 2020-02-02 3
4 2020-03-01 1834
5 2020-03-02 5

Perform Function on 1 Column Table in Oracle [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
I have a table with 1 column:
id
1
2
3
4
5
6
7
8
9
and I want the following output:
11
22
33
41
52
63
71
82
93
I am using Oracle.
you can try like below using case when
select case when (id*11)<=33 then (id*11)
when (id*11)>33 and (id*11)<70 then (id*11)-3
else (id*11)-6 end as col
from your_table
demo link
output
COL
11
22
33
41
52
63
71
82
93

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

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.