|
Поиск максимального значения в столбце таблицы
|
|||
---|---|---|---|
#18+
Здравствуйте Всем! Есть таблица и один из столбцов содержит порядковые номера записей новых. Они могут идти не попорядку т.е. 1 3 10 5 7 8 Как мне определить максимальный элемент в столбце. Может есть какая функция, возвращающая его? Заранее большое спасибо. ... |
|||
:
Нравится:
Не нравится:
|
|||
10.04.2014, 17:43 |
|
Поиск максимального значения в столбце таблицы
|
|||
---|---|---|---|
#18+
dima_18, CALCULATE MAX() ... |
|||
:
Нравится:
Не нравится:
|
|||
10.04.2014, 17:48 |
|
Поиск максимального значения в столбце таблицы
|
|||
---|---|---|---|
#18+
Здравствуйте IgorNG ! Большое спасибо за ответ. А я могу переменной присвоить это: lastnom = CALCULATE MAX() - так конструкция не проходит? или как синтаксис написать? таблица у меня obsled2 столбец в котором это хочу сделать par2 т.е. lastnom = CALCULATE MAX(obsled2.par2) - ? выдает ошибку ... |
|||
:
Нравится:
Не нравится:
|
|||
10.04.2014, 17:53 |
|
Поиск максимального значения в столбце таблицы
|
|||
---|---|---|---|
#18+
dima_18, А хэлп почитать? Performs financial and statistical operations on fields in a table or on expressions involving fields. CALCULATE eExpressionList [Scope] [FOR lExpression1] [WHILE lExpression2] [TO VarList | TO ARRAY ArrayName] [NOOPTIMIZE] [IN nWorkArea | cTableAlias] Parameters eExpressionList Specifies the expressions that can contain any combination of the following functions: AVG(nExpression) CNT( ) or COUNT( ) MAX(eExpression) MIN(eExpression) NPV(nExpression1, nExpression2 [, nExpression3]) STD(nExpression) SUM(nExpression) VAR(nExpression) Functions in the expression list eExpressionList are separated by commas. These functions are specific to CALCULATE and are described in detail later in this section. They should not be confused with similarly named independent functions. For example, CALCULATE MIN( ) is not the same as MIN( ). Scope Specifies a range of records used in the calculation. Only the records that fall within the range of records are included in the calculation. The scope clauses are: ALL, NEXT nRecords, RECORD nRecordNumber, and REST. For more information, see Scope Clauses. Commands that include Scope operate only on the table in the active work area. The default scope for CALCULATE is ALL records. FOR lExpression1 Specifies that only the records that satisfy the logical condition lExpression1 are included in the calculation. Including a FOR clause conditionally includes records in the calculation, filtering out undesired records. Rushmore Query Optimization optimizes a CALCULATE ... FOR query if lExpression1 is an optimizable expression. For best performance, use an optimizable expression in the FOR clause. For information on Rushmore optimizable expressions, see SET OPTIMIZE Command and Using Rushmore Query Optimization to Speed Data Access. WHILE lExpression2 Specifies a condition whereby records are included in the calculation as long as the logical expression lExpression2 evaluates to true (.T.). TO VarList Specifies one or more variables to which the results of the calculation are stored. If a variable you specify does not exist, Visual FoxPro automatically creates the variable with the name you specify. TO ARRAY ArrayName Specifies an array name to which the results of the calculation can be stored. If the array name you specify does not exist, Visual FoxPro automatically creates an array with the name you specify. If the array exists and is not large enough to contain all the results of the calculation, Visual FoxPro automatically increases the size of the array to accommodate the information. If an existing array is larger than necessary, additional elements are left unchanged. Results are stored to the array elements in the order they are specified in the CALCULATE command. NOOPTIMIZE Disables Rushmore optimization of CALCULATE. For more information, see SET OPTIMIZE Command and Using Rushmore Query Optimization to Speed Data Access. AVG( nExpression) Computes the arithmetic mean of nExpression. Only records meeting the Scope and/or optional FOR or WHILE conditions are included in the result. CNT( ) or COUNT( ) Returns the number of records in the table. Only records meeting the Scope and/or optional FOR or WHILE conditions are included in the result. MAX( eExpression) Returns the highest or latest value of eExpression. Within the MAX( ) clause, you can specify any character, date, datetime, numeric, float, integer, double, or currency field, or any expression using fields of these types. Only records meeting the Scope and/or optional FOR or WHILE conditions are included in the result. MIN( eExpression) Returns the lowest or earliest value of eExpression. Any character, date, datetime, numeric, float, integer, double, or currency field, or any valid expression using fields of these types, can be included in eExpression. Only records meeting the Scope and/or optional FOR or WHILE conditions are included in the result. NPV( nExpression1, nExpression2[, nExpression3]) Computes the net present value of a series of future cash flows discounted at a constant periodic interest rate. nExpression1 specifies the interest rate expressed as a decimal value. nExpression2 specifies a field, field expression, or a numeric expression representing a series of cash flows. Each cash flow can be either positive or negative. In cases where nExpression2 is a field, the value for each record in the field is considered a cash flow. nExpression3 specifies an optional initial investment. If the initial investment is not included, then the initial investment is assumed to occur at the end of the first period. This initial investment is the first record in the field and is negative to represent a cash outflow. Only records meeting the Scope and/or optional FOR or WHILE conditions are included in the result. STD( nExpression) Computes the standard deviation of nExpression. The standard deviation measures the degree to which the values of fields or expressions involving fields differ from the average of all the values. The smaller the standard deviation, the less the values vary from the average. Only records meeting the Scope and/or optional FOR or WHILE conditions are included in the result. SUM( nExpression) Totals the values of nExpression. Only records meeting the Scope and/or optional FOR or WHILE conditions are included in the result. VAR( nExpression) Computes the variance from the average of nExpression. The variance is the standard deviation squared. The smaller the variance, the less the values vary from the average. Only records meeting the Scope and/or optional FOR or WHILE conditions are included in the result. IN nWorkArea| cTableAlias Specifies the workarea or table alias affected by the CALCULATE command. Use this clause to specify a workarea or a table outside the current work area. Remarks Records containing the null value are not included in the operations that CALCULATE performs. Example Copy Code CLOSE DATABASES OPEN DATABASE (HOME(2) + 'data\testdata') USE orders && Open Orders table SET TALK ON CLEAR CALCULATE AVG(order_amt), MIN(order_amt), MAX(order_amt) CALCULATE STD(order_amt), VAR(order_amt) TO gnStd, gnVar ... |
|||
:
Нравится:
Не нравится:
|
|||
10.04.2014, 17:57 |
|
Поиск максимального значения в столбце таблицы
|
|||
---|---|---|---|
#18+
спасибо, извиняюсь не сообразил сразу! ... |
|||
:
Нравится:
Не нравится:
|
|||
10.04.2014, 18:05 |
|
Поиск максимального значения в столбце таблицы
|
|||
---|---|---|---|
#18+
Код: sql 1. 2. 3.
... |
|||
:
Нравится:
Не нравится:
|
|||
11.04.2014, 11:30 |
|
Поиск максимального значения в столбце таблицы
|
|||
---|---|---|---|
#18+
pipos522 Код: sql 1. 2. 3.
А INSERT то зачем? ... |
|||
:
Нравится:
Не нравится:
|
|||
11.04.2014, 11:42 |
|
Поиск максимального значения в столбце таблицы
|
|||
---|---|---|---|
#18+
IgorNG, Например есть справочник проиндексированный по табельному номеру, и есть поле номер карты. Это так примерчик как добавить строчку с +1 номер карты. ... |
|||
:
Нравится:
Не нравится:
|
|||
11.04.2014, 11:59 |
|
Поиск максимального значения в столбце таблицы
|
|||
---|---|---|---|
#18+
pipos522IgorNG, Например есть справочник проиндексированный по табельному номеру, и есть поле номер карты. Это так примерчик как добавить строчку с +1 номер карты.а теперь посадите на ввод данных несколько операторов и очешуейте :) ... |
|||
:
Нравится:
Не нравится:
|
|||
11.04.2014, 12:30 |
|
Поиск максимального значения в столбце таблицы
|
|||
---|---|---|---|
#18+
tanglir, USE table_1 SHARED + SET REFRESH TO или просто через таймер реврешить часто таблу. Думаешь не прокатит? (на несколько пользователей одну прогр. не делал еще ) ... |
|||
:
Нравится:
Не нравится:
|
|||
11.04.2014, 14:51 |
|
Поиск максимального значения в столбце таблицы
|
|||
---|---|---|---|
#18+
pipos522 (на несколько пользователей одну прогр. не делал еще ) Если соберешься делать - сначала почитай теорию про особенности разработки многопользовательских приложений. И так как выше написал не вздумай там делать. ... |
|||
:
Нравится:
Не нравится:
|
|||
11.04.2014, 15:15 |
|
Поиск максимального значения в столбце таблицы
|
|||
---|---|---|---|
#18+
Например: 1) есть 2 компа с одинаковой программой 2) база данных на сервере одна на двоих далее без SHARED мне кажется не обойтись или открываются как-то по другому? (разобраться хочется) ... |
|||
:
Нравится:
Не нравится:
|
|||
11.04.2014, 16:08 |
|
Поиск максимального значения в столбце таблицы
|
|||
---|---|---|---|
#18+
без SHARED не обойтись, но это только начало. ... |
|||
:
Нравится:
Не нравится:
|
|||
11.04.2014, 16:15 |
|
Поиск максимального значения в столбце таблицы
|
|||
---|---|---|---|
#18+
Дяльше подумай что будет если код сработает одновременно в одно и тоже время, вот так ПК1ПК2CALCULATE max(lkarta) TO nnCALCULATE max(lkarta) TO nn insert into spisok (lkarta) values ( nn+1)insert into spisok (lkarta) values ( nn+1) ... |
|||
:
Нравится:
Не нравится:
|
|||
11.04.2014, 16:19 |
|
Поиск максимального значения в столбце таблицы
|
|||
---|---|---|---|
#18+
Error ( append blank тоже самое будет заливать в другую таблицу и на закрытии программы в общую базу всё выплюнуть ? ... |
|||
:
Нравится:
Не нравится:
|
|||
11.04.2014, 16:28 |
|
Поиск максимального значения в столбце таблицы
|
|||
---|---|---|---|
#18+
pipos522Error ( Ошибок не будет. Читай книжки про разработку многопользовательских приложений. ... |
|||
:
Нравится:
Не нравится:
|
|||
11.04.2014, 16:39 |
|
Поиск максимального значения в столбце таблицы
|
|||
---|---|---|---|
#18+
pipos522Error ( append blank тоже самое будет заливать в другую таблицу и на закрытии программы в общую базу всё выплюнуть ? Ага, а до этого каждый пользователь со своей базой будет работать! ... |
|||
:
Нравится:
Не нравится:
|
|||
11.04.2014, 16:51 |
|
Поиск максимального значения в столбце таблицы
|
|||
---|---|---|---|
#18+
Dima TДaльше подумай что будет если код сработает одновременно в одно и тоже время, вот так ПК1ПК2CALCULATE max(lkarta) TO nnCALCULATE max(lkarta) TO nn insert into spisok (lkarta) values ( nn+1)insert into spisok (lkarta) values ( nn+1) Если рассматривать именно такое решение, то могут быть варианты... Например, на "больших" серверах (MS SQL, Oracle и др.) это решается созданием уникального ключа по полю. Тогда одна запись запишется, а вторая вызовет исключение. Программа должна это исключение поймать, вычислить новое значение и направить повторный insert... Хотя, на мой вкус, автоинкремент или sequences лучше... ... |
|||
:
Нравится:
Не нравится:
|
|||
11.04.2014, 21:26 |
|
Поиск максимального значения в столбце таблицы
|
|||
---|---|---|---|
#18+
Станислав С...киймогут быть варианты... я поэтому и написал Dima TЧитай книжки про разработку многопользовательских приложений. Чтобы тут все варианты не перечислять. Тем более что надо все знать, т.к. одного идеального решения нет. ... |
|||
:
Нравится:
Не нравится:
|
|||
12.04.2014, 06:29 |
|
|
start [/forum/topic.php?fid=41&fpage=33&tid=1582679]: |
0ms |
get settings: |
9ms |
get forum list: |
11ms |
check forum access: |
3ms |
check topic access: |
3ms |
track hit: |
28ms |
get topic data: |
10ms |
get forum data: |
2ms |
get page messages: |
47ms |
get tp. blocked users: |
1ms |
others: | 301ms |
total: | 415ms |
0 / 0 |