Re: auto_increment every year

2003-02-17 Thread alx
On Mon, 2003-02-17 at 12:57, [EMAIL PROTECTED] wrote:
 Your message cannot be posted because it appears to be either spam or
 simply off topic to our filter. To bypass the filter you must include
 one of the following words in your message:
 
 sql,query,queries,smallint
 
 If you just reply to this message, and include the entire text of it in the
 reply, your reply will go through. However, you should
 first review the text of the message to make sure it has something to do
 with MySQL. Just typing the word MySQL once will be sufficient, for example.
 
 You have written the following:
 
 HI all
 I'm searching in how to generate a auto_increment number starting form 1
 every year
 I mean
 
 ID DATE
 1  2003
 2  2003
 
 1  2004
 2  2004
 etc
 maybe possible or I've to use some c code to make it possible ?
 
 TIA
 Alx
 -- 
 int a=1,b,c=2800,d,e,f[2801],g;main(){for(;b-c;) f[b++]=a/5;
 for(;d=0,g=c*2;c-=14,printf(%.4d,e+d/a),e=d%a)for(b=c;d+=f[b]*a,
 f[b]=d%--g,d/=g--,--b;d*=b);}
 
 
-- 
int a=1,b,c=2800,d,e,f[2801],g;main(){for(;b-c;) f[b++]=a/5;
for(;d=0,g=c*2;c-=14,printf(%.4d,e+d/a),e=d%a)for(b=c;d+=f[b]*a,
f[b]=d%--g,d/=g--,--b;d*=b);}


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: Re: auto_increment every year

2003-02-17 Thread Paul DuBois
sql,query,queries,smallint



   HI all

  I'm searching in how to generate a auto_increment number starting form 1
  every year
  I mean

  ID DATE
  1  2003
  2  2003
  
  1  2004
  2  2004
  etc

   maybe possible or I've to use some c code to make it possible ?


Yes, this is possible.  Use a MyISAM table and set up a composite
index on the two columns, with the AUTO_INCREMENT column as the
second column in the index.

CREATE TABLE t
(
 yr   YEAR NOT NULL,
 id   INT UNSIGNED NOT NULL AUTO_INCREMENT,
 PRIMARY KEY(yr,id)
) TYPE = MyISAM;

This will generate an independent sequence of numbers for each distinct
yr value.

INSERT INTO t (yr) VALUES(2003),(2003),(2004),(2005),(2005);
SELECT * FROM t;

+--++
| yr   | id |
+--++
| 2003 |  1 |
| 2003 |  2 |
| 2004 |  1 |
| 2005 |  1 |
| 2005 |  2 |
+--++

-
Before posting, please check:
  http://www.mysql.com/manual.php   (the manual)
  http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php