473,386 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Queries - MAX function

doma23
107 100+
I have next table from a query:

Values.....Start
25..............0
26..............0
27..............1
28..............0
29..............0
30..............0

What I'm trying to accomplish is to divide all the values with the value in which the start field is 1; in this case, with 27.
I've done this easily with 2 queries, however I have a large set of this data and I would like to simplify it by putting everything into 1 query.
Can this be done?

Thank you!
Oct 26 '10 #1

✓ answered by Mariostg

select values, values/(select max(start) from MyTable) from MyTable

5 2109
Mariostg
332 100+
select values, values/(select max(start) from MyTable) from MyTable
Oct 26 '10 #2
doma23
107 100+
Thank you!

Just a little correction. The code you provided gave me an insight how it should work ("sub sql inside sql"), but the correct code is a bit different as you probably misunderstood that I need to divide it with max value in start field.
I actually needed to divide it with max value in Values field where value of teh Start field is 1.
So the correct code is this:
Expand|Select|Wrap|Line Numbers
  1. SELECT tblTest.Values, [tbltest].[Values]/(SELECT tblTest.Values
  2. FROM tblTest
  3. GROUP BY tblTest.Values, tblTest.Start
  4. HAVING (((tblTest.Start)=1))) AS Divided
  5. FROM tblTest;
Oct 26 '10 #3
doma23
107 100+
Hmm..Now I have another question, which brings me back in a way to my initial question.

What if the figures in the Start field were not of boolean type. What if they were 1,2,5,3,4; and I need to divide it by max value which is in this case 5.
I tried to do it, but it gives me back all values. Here is the SQL:

Expand|Select|Wrap|Line Numbers
  1. SELECT Max(tblTest.Start) AS MaxDiStart, tblTest.Values
  2. FROM tblTest
  3. GROUP BY tblTest.Values;
Oct 27 '10 #4
Mariostg
332 100+
Hi. Yeah I misunderstood your question.
To answer post #4, try this:
Expand|Select|Wrap|Line Numbers
  1. SELECT Top 1 Values,Start
  2. SORT BY Start DESC
  3.  
This select values and start, sort by descending order of Start and return the first row.
And I guess your post #3 is what you wanted regarding the division issue...
Oct 27 '10 #5
NeoPa
32,556 Expert Mod 16PB
You need a double-subquery. It's possible to do it with just the one and some string manipulation, but the most logical way is like this :
Expand|Select|Wrap|Line Numbers
  1. SELECT [Values]
  2.      , [Values]/(
  3.     SELECT TOP 1
  4.            [Values]
  5.     FROM   [tblTest]
  6.     WHERE  ([Start] = (
  7.         SELECT Max([Start])
  8.         FROM   [tblTest]
  9.         )
  10.     ) AS Divided
  11. FROM   [tblTest]
Oct 27 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used...
8
by: Ian Davies | last post by:
Hello I am trying to run a few INSERT queries only if the user clicks 'continue' in a <a href> The queries takes variables created from SELECT queries. I have tried to acheive this by putting The...
1
by: John E | last post by:
I have an Access 2000 database in which there are remotely linked SQL tables and a couple of local tables. If I have queries in Access that are designed to pass data between these remote linked...
0
by: Zlatko Matić | last post by:
Hi everybody! Recently I was struggling with client/server issues in MS Access/PostgreSQL combination. Although Access is intuitive and easy to use desktop database solution, many problems...
11
by: BillCo | last post by:
Does anyone know of a way to search through the SQL code of queries to find table name matches? Bear in mind there are literilly 1000's of queries in this database and doing it the old fashioned...
35
by: NickName | last post by:
I understand it's easy to list all saved queries of a given Access database via Msysobjects system table. However, I have not seen any posting over this NG or other similar ones that also include...
8
by: =?Utf-8?B?TWFnZ2ll?= | last post by:
hi, I have an Access database that uses some queries that call a function for formatting purposes. They work just fine. I am starting to develop an application in asp.net (VS 2005) using this...
6
by: AdmiralXizor | last post by:
I have written a function that executes action parameter queries given a name and a list of parameters. It splits a string into an array, passes the parameters to the (already saved) query name,...
0
MMcCarthy
by: MMcCarthy | last post by:
Rather than using the Access design view change the view to SQL. I am going to attempt to outline the general syntax used for SQL queries in Access. Angle brackets <> are used in place of some...
5
by: Anthony2oo5 | last post by:
I wrote this function about 2 years ago when I started in PHP, I haven't touched PHP since so im still not an expert, but I would like to know what people thought of it, and if was any good / secure...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.