home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 May (DVD) / Macworld Resource DVD May 2003.toast / Data / Software / Bonus / Database / mysql-max-3.23.55.sit / mysql-max-3.23.55-apple-darwi.1 / mysql-test / t / having.test < prev    next >
Encoding:
Text File  |  2003-01-21  |  1.8 KB  |  51 lines  |  [TEXT/ttxt]

  1. # test of problems with having (Reported by Mark Rogers)
  2. #
  3.  
  4. drop table if exists t1,t2;
  5. create table t1 (a int);
  6. select count(a) as b from t1 where a=0 having b > 0;
  7. insert into t1 values (null);
  8. select count(a) as b from t1 where a=0 having b > 0;
  9. select count(a) as b from t1 where a=0 having b >=0;
  10. drop table t1; 
  11.  
  12. #
  13. # Test of problem with HAVING and AVG()
  14. #
  15.  
  16. CREATE TABLE t1 (
  17.   raw_id int(10) NOT NULL default '0',
  18.   chr_start int(10) NOT NULL default '0',
  19.   chr_end int(10) NOT NULL default '0',
  20.   raw_start int(10) NOT NULL default '0',
  21.   raw_end int(10) NOT NULL default '0',
  22.   raw_ori int(2) NOT NULL default '0'
  23. );
  24.  
  25. INSERT INTO t1 VALUES (469713,1,164123,1,164123,1),(317330,164124,317193,101,153170,1),(469434,317194,375620,101,58527,1),(591816,375621,484273,1,108653,1),(591807,484274,534671,91,50488,1),(318885,534672,649362,101,114791,1),(318728,649363,775520,102,126259,1),(336829,775521,813997,101,38577,1),(317740,813998,953227,101,139330,1),(1,813998,953227,101,139330,1);
  26.  
  27. CREATE TABLE t2 (
  28.   id int(10) unsigned NOT NULL default '0',
  29.   contig_id int(10) unsigned NOT NULL default '0',
  30.   seq_start int(10) NOT NULL default '0',
  31.   seq_end int(10) NOT NULL default '0',
  32.   strand tinyint(2) NOT NULL default '0',
  33.   KEY id (id)
  34. );
  35. INSERT INTO t2 VALUES (133195,469713,61327,61384,1),(133196,469713,64113,64387,1),(133197,1,1,1,0),(133197,1,1,1,-2);
  36. SELECT e.id,
  37.    MIN( IF(sgp.raw_ori=1,
  38.           (e.seq_start+sgp.chr_start-sgp.raw_start),  
  39.           (sgp.chr_start+sgp.raw_end-e.seq_end))) as start, 
  40.    MAX( IF(sgp.raw_ori=1,
  41.            (e.seq_end+sgp.chr_start-sgp.raw_start),  
  42.            (sgp.chr_start+sgp.raw_end-e.seq_start))) as end, 
  43.    AVG(IF (sgp.raw_ori=1,e.strand,(-e.strand))) as chr_strand 
  44. FROM  t1 sgp,
  45.       t2 e  
  46. WHERE sgp.raw_id=e.contig_id 
  47. GROUP BY e.id 
  48. HAVING chr_strand= -1 and end >= 0 
  49.   AND start <= 999660;
  50. drop table t1,t2;
  51.