![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Запросы [D7]
Клара © (2006-12-08 10:26:00)Есть таблица персонала, поля: Dat_R, Age(вычисляется).
Нужно разбить данные по возрастным группам: от20 до 29, от 30 до 39 и т.д и т.п
Anatoly Podgoretsky (2006-12-08 11:32:00) [61]> oxffff (08.12.2006 11:17:26) [26]
не "кратны М"),
Клара (2006-12-08 11:31:00) [62]
> oxffff
Вы перегрелись, раслабтесь и улыбнитесь.
Ничего обидного. А я пока займусь практикой.
oxffff (2006-12-08 11:28:00) [63]
> Клара (08.12.06 11:25) [30]
>
> > oxffff
>
> Для каких СУБД. И кто автор.
Вы говорите загадками. Опять не понял вас.
Что вы хотите?
Клара (2006-12-08 11:27:00) [64]
> oxffff
Я о размере справки.
Клара (2006-12-08 11:25:00) [65]
> oxffff
Для каких СУБД. И кто автор.
oxffff (2006-12-08 11:24:00) [66]
> Клара (08.12.06 11:21) [27]
>
> > oxffff
>
> Это что бы мало не показалось. Отстань мол.
> Я приму к сведению.
НЕ понял тебя?
oxffff (2006-12-08 11:23:00) [67]То есть в твоем случае будет
select case age
...
WHEN age>20 and age<30 THEN 3
WHEN age>30 and age<40 THEN 4
...
end
as agegroup,
count(agegroup) from person group by agegroup
Естественно можно вместо THEN 3 писать THEN '20-29'.
Это есть в MS SQL. Что касаемо ACCESS, то не знаю
Клара (2006-12-08 11:21:00) [68]
> oxffff
Это что бы мало не показалось. Отстань мол.
Я приму к сведению.
Клара (2006-12-08 11:17:00) [69]
> Anatoly Podgoretsky
О чем речь?
oxffff (2006-12-08 11:17:00) [70]Если возрастные группы неравномерны ( то есть не "кратны 10"), то CASE
Evaluates a list of conditions and returns one of multiple possible result expressions.
CASE has two formats:
The simple CASE function compares an expression to a set of simple expressions to determine the result.
The searched CASE function evaluates a set of Boolean expressions to determine the result.
Both formats support an optional ELSE argument.
Transact-SQL Syntax Conventions
Syntax
Simple CASE function:
CASE input_expression
WHEN when_expression THEN result_expression
[ ...n ]
[
ELSE else_result_expression
]
END
Searched CASE function:
CASE
WHEN Boolean_expression THEN result_expression
[ ...n ]
[
ELSE else_result_expression
]
END
Arguments
input_expression
Is the expression evaluated when the simple CASE format is used. input_expression is any valid expression.
WHEN when_expression
Is a simple expression to which input_expression is compared when the simple CASE format is used. when_expression is any valid expression. The data types of input_expression and each when_expression must be the same or must be an implicit conversion.
n
Is a placeholder that indicates that multiple WHEN when_expression THEN result_expression clauses, or multiple WHEN Boolean_expression THEN result_expression clauses can be used.
THEN result_expression
Is the expression returned when input_expression equals when_expression evaluates to TRUE, or Boolean_expression evaluates to TRUE. result expression is any valid expression.
ELSE else_result_expression
Is the expression returned if no comparison operation evaluates to TRUE. If this argument is omitted and no comparison operation evaluates to TRUE, CASE returns NULL. else_result_expression is any valid expression. The data types of else_result_expression and any result_expression must be the same or must be an implicit conversion.
WHEN Boolean_expression
Is the Boolean expression evaluated when using the searched CASE format. Boolean_expression is any valid Boolean expression.
Result Types
Returns the highest precedence type from the set of types in result_expressions and the optional else_result_expression. For more information, see Data Type Precedence (Transact-SQL).
Anatoly Podgoretsky (2006-12-08 11:11:00) [71]> Клара (08.12.2006 11:07:23) [23]
Ну почему не мне, я тоже не против.
У тебя вопрос плохо поставлен, пришлось много кратно уточнять.
А у меня сегодня телепатор свежий.
Клара (2006-12-08 11:07:00) [72]
> Anatoly Podgoretsky
А это я не Вам. Но за совет спасибо.
Клара (2006-12-08 11:05:00) [73]
> oxffff
Если честно, мне нравится идея, но ничего похожего я не видела.
А можно расписать CASE
oxffff (2006-12-08 11:05:00) [74]Anatoly Podgoretsky © (08.12.06 11:01) [19]
Ну или действительно так элегантнее.
Anatoly Podgoretsky (2006-12-08 11:03:00) [75]> Клара (08.12.2006 10:54:12) [12]
Конечно скучно и почему бы не поразвлекаться, пока не будет задан вопрос?
Anatoly Podgoretsky (2006-12-08 11:01:00) [76]> Клара (08.12.2006 10:26:00) [0]
Привести к целому и поделить на 10
По этому значению группировать и вычислять количество
Клара (2006-12-08 11:01:00) [77]
> oxffff
Pers(tabn,surname,name,data_r,adres,...)
oxffff (2006-12-08 10:59:00) [78]О пардон ошибся
select id,case age .. as agegroup,count(agegroup) from person group by id,agegroup
не sum, а count Конечно же
Клара (2006-12-08 10:58:00) [79]
> Sergey13
Я попробую! Спасибо
oxffff (2006-12-08 10:57:00) [80]Приведи описание таблицы.