473,398 Members | 2,812 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,398 software developers and data experts.

Auto Increment on the fly...

Have a query:
SELECT sum(Sales)AS TotSales, SalesManager
FROM Data
WHERE Region = 'East'
GROUP BY SalesManager
ORDER BY TotSales DESC

Is there a way of creating an autoincrement field

SELECT sum(Sales)AS TotSales, SalesManager, something like
...autoincrement( xxx) AS Rank
FROM Data
WHERE Region = 'East'
GROUP BY SalesManager
ORDER BY TotSales DESC

100 John 1
75 Mary 2
50 Ted 3

etc....

thanks

jrt


Jul 19 '05 #1
2 21938
John Thorne wrote:
Have a query:
SELECT sum(Sales)AS TotSales, SalesManager
FROM Data
WHERE Region = 'East'
GROUP BY SalesManager
ORDER BY TotSales DESC

Is there a way of creating an autoincrement field

SELECT sum(Sales)AS TotSales, SalesManager, something like
..autoincrement( xxx) AS Rank
FROM Data
WHERE Region = 'East'
GROUP BY SalesManager
ORDER BY TotSales DESC

100 John 1
75 Mary 2
50 Ted 3

etc....

thanks

jrt


Use a user variable. Something like

SELECT @m:=0;
SELECT sum(Sales) AS TotSales, SalesManager, @m:=@m+1 AS Rank
etc.

http://www.mysql.com/doc/en/Variables.html

Jul 19 '05 #2
John Thorne wrote:
Have a query:
SELECT sum(Sales)AS TotSales, SalesManager
FROM Data
WHERE Region = 'East'
GROUP BY SalesManager
ORDER BY TotSales DESC

Is there a way of creating an autoincrement field

SELECT sum(Sales)AS TotSales, SalesManager, something like
..autoincrement( xxx) AS Rank
FROM Data
WHERE Region = 'East'
GROUP BY SalesManager
ORDER BY TotSales DESC

100 John 1
75 Mary 2
50 Ted 3

etc....

thanks

jrt


Use a user variable. Something like

SELECT @m:=0;
SELECT sum(Sales) AS TotSales, SalesManager, @m:=@m+1 AS Rank
etc.

http://www.mysql.com/doc/en/Variables.html

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: diong | last post by:
i have a field with a list of wrong ID (random) and i wish to replac them with a sequential (auto-increment) value. how to remove the valu and to add in the sequential ID? Im a newbie in ASP! Pls...
2
by: Tom | last post by:
I am trying to store information into a table that has an auto increment field. There is currently no data in the table. Using the code below I cannot insert data into the table. I get an error...
5
by: Paulovič Michal | last post by:
hi all, I have problem with SERIAL field type (or sequence functionality). I have table with three columns - ID, IDS, NAME. I want auto-increment IDS grouped by ID. Example: 1, 1, Ferdo 1, 2,...
5
by: vul | last post by:
In VB6 there is Auto Increment check box in Project Properties, which allow you have a new version every time you compile the project. Is there any easy way to have this feature in VB 2005? Some...
2
by: john | last post by:
Is it true that if I split my access database in backend and frontend and I implement custom auto increment for the ID fields, that my database is ready to be used in a multi-user environment? I...
1
by: rhepsi | last post by:
hii all, i have created a database with a table with number of fields....in msaccess ive set primary key as SNo: and its datatype as auto number... How to set the auto increment ???? ...
0
chumlyumly
by: chumlyumly | last post by:
Hello scripters - OS: Mac OSX Language: PHP w/ MySQL database I've created an insert page where a user inputs his info, which then goes to four different tables in a MySQL database. The...
1
by: jimilives | last post by:
I forgot to turn on auto increment when I reinstalled this database and now I have a bunch of NULL values in my ID field for last few hundred inserts, how can I update this table to replace the NULLS...
13
by: BobLewiston | last post by:
Using Visual C# 2008 Express and SQL Server 2008 Express, I would like to insert new records into database "AdventureWorks", table "Person.Contact". To my surprise, this table's int-value identity...
3
by: paulyXvpf | last post by:
Hello, all... Just finished a handy tutorial that has helped me understand how to auto increment and post to a web page... but its only a Web User Control passing values from VB.NET method...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.