Hello guys, i have 3 questions concerning sql-select statements.
1)
Suppose i have a group by select statement, then i need for every column that is not used in group by an aggregate function:
select
id
min(date)
min(name)
...
FROM
table
GROUP BY id
Is there any way to avoid all this aggregate functions?
2)
afaik i cann't use the column aliases in the same select case:
select
convert(int,(a+b)) as id
convert(int,b) as name
case
When id = 20 THEN 1
...
End
Is there any way i can use an aliase here instead of convert(int,(a+b)) all the time?
3)
Suppose i have the following table:
id | val_a | val_b
1 | 10 | NULL
2 | 29 | 92
3 | 39 | NULL
Now i am asking for a select statement that counts all the rows and also counts the val_b rpws wjere val_b = NULL. Do i have to work around with count(*) - count(val_b)?
Thx for your advices
1)
Suppose i have a group by select statement, then i need for every column that is not used in group by an aggregate function:
select
id
min(date)
min(name)
...
FROM
table
GROUP BY id
Is there any way to avoid all this aggregate functions?
2)
afaik i cann't use the column aliases in the same select case:
select
convert(int,(a+b)) as id
convert(int,b) as name
case
When id = 20 THEN 1
...
End
Is there any way i can use an aliase here instead of convert(int,(a+b)) all the time?
3)
Suppose i have the following table:
id | val_a | val_b
1 | 10 | NULL
2 | 29 | 92
3 | 39 | NULL
Now i am asking for a select statement that counts all the rows and also counts the val_b rpws wjere val_b = NULL. Do i have to work around with count(*) - count(val_b)?
Thx for your advices