萌新SQL基础学习1---续2

INSERT INTO语句(下面我都未插入id列,因为我设置的是自增)

插入一行

INSERT INTO user (username,birthday,sex,address) values("萧华","2020-10-30","男","御雷宗");   

birthday字段我设置的是Date类型,用于存储年月日,显示XXXX-XX-XX


在指定的列插入数据(必须清楚数据库中哪些列允许NULL)

INSERT INTO user(username,address) values("孙悟空","花果山");



UPDATE语句(警告:若使用没有where语句的UPDATE语句会将表中所有数据的那列全部修改

UPDATE user SET address="水帘洞",sex=2 where username="孙悟空";

 


DELETE语句

DELETE FROM user  WHERE username="张小";


若需要在不删除表的前提下删除表中所有的数据可以:

DELETE * FROM user;或者 DELETE FROM user;


SELECT TOP,LIMIT,ROWNUM子句

SELECT TOP用于规定要返回的记录的数目(并非所有数据库都支持SELECT TOP子句,此处用MYSQL做示例

SELECT * FROM user LIMIT 3;


SELECT TOP 50 PERCENT * FROM user;(SQL Server中可以使用)

上条语句在MYSQL中无法执行,须换成LIMIT关键字,介于两者之间的可以用where加运算符或者LIMIT 1,3;


LIEK操作符

用于在WHERE子句中搜索列中的指定模式

SELECT * FROM user WHERE username LIKE '张%';表示从user表中选取username列中首字符为“张”的一行

这里单双引号都可以用,之后除非不可一样使用,否则不指出

提示:“%”符号用于在模式的前后定义通配符(缺省字母)。

“%明”表示最后一个为“明”;“%小%”表示包含“小”(无论首尾中间)。且可以通过NOT关键字表示选取不匹配的记录

如:SELECT * FROM user WHERE username NOT LIKE"%张%";



通配符

在SQL中,通配符与SQL LIKE操作符一起使用。(%上面用过,在此就不再说了)

通配符 描述
% 替代0个或多个字符
_ 替代一个字符
[charlist] 字符列中的任何单一字符
[^charlist]

[!charlist]
不在字符列中的任何单一字符
SELECT * FROM user WHERE username LIKE "_小明"; 这里的“_”可以放在任意位置


SELECT * FROM user WHERE username REGEXP "^[张孙]"; 我写中文没选取我想要的(选取以张/孙开头的username),明早在解决。。。


萌新求助

12-23

这是一个管理系统的一部分,链表标红输不出结果,最上面是一些声明和读入文件的函数,最下面是主函数,求原因rn#include rn#include rnfloat balance[10000];//银行卡余额rnint mark[10000];//标记数组rnstruct Fruit//五种水果rnrn char fname[20];rn fruit[5];rnrnstruct Info//小票信息rnrn int id;//序号rn int ftype;//水果种类rn float price;//单价rn float fnum;// 数量rn float total;//总价rn float pay;//付款rn float ret;//找零rn int cardid;//卡号rn float befpay;//购物前余额rn float aftpay;//购物后余额rn int hour;//小时rn int minute; //分钟rn struct Info *next;rn info[30];rnrnvoid read()//读入内存rnrn FILE *fp;rn if((fp=fopen("data.txt","r"))==NULL)rn rn printf("数据不存在\n");rn return ;rn rn int i,j;rn char fname[20];rn for(i=0; i<30; i++) //把data文件读入内存rn rn fscanf(fp,"%d%s%f%f%f%f%f%d%f%f%d%d",rn &info[i].id,rn fname,rn &info[i].fnum,rn &info[i].total,rn &info[i].pay,rn &info[i].ret,rn &info[i].cardid,rn &info[i].befpay,rn &info[i].aftpay,rn &info[i].hour,rn &info[i].minutern );rnrn for (j=0; j<5; j++) //录入水果代表的数字rn if(!strcmp(fname,fruit[j].fname))//如果两个相等,执行下面语句rn rn info[i].ftype=j;rn break;rn rn mark[info[i].id]=1;rn rn if((fp=fopen("vip.txt","r"))==NULL)rn rn printf("会员信息不存在\n");rn return ;rn rn int num;rn fscanf(fp,"%d",&num);rn int u,v;rn for (i=0; i=x&&info[i].total<=y)rn rn if(!tmp)rn rn tmp=&info[i];rn head=tmp;rn rn elsern rn tmp->next=&info[i];rn tmp=tmp->next;rn rn rn rn printf("序号 种类 单价 数量 总价 支付 找零 卡号 购前 购后\n");rn while(head)rn rn printf("%4.4d %s %.2f %.2f %.2f %.2f %.2f %d %.2f %.2f",rn info[i].id,rn fruit[info[i].ftype].fname,rn info[i].price,rn info[i].fnum,rn info[i].total,rn info[i].pay,rn info[i].ret,rn info[i].cardid,rn info[i].befpay,rn info[i].aftpay);rn printf("时间: %d:%d\n",info[i].hour,info[i].minute);rn rn[/color]rnint main()rnrn int op;rn int i;rn for (i=0; i<10000; i++)rn mark[i]=0;//标记id是否出现rn strcpy(fruit[0].fname,"苹果");rn strcpy(fruit[1].fname,"香蕉");rn strcpy(fruit[2].fname,"西瓜");rn strcpy(fruit[3].fname,"桃子");rn strcpy(fruit[4].fname,"橘子");rn printf("************************************************************************************************************************\n");rn printf("************************************************************************************************************************\n");rn printf("\n\n\t\t 欢迎来到水果超市管理系统!(* ^_^ *)\n\n");rn printf("************************************************************************************************************************\n");rn printf("\n\t\t 请输入操作:\n\t\t1、添加记录\n\t\t2、修改\n\t\t3、删除\n\t\t4、查询\n\t\t5、统计\n\t\t6、会员\n\t\t7、大额购物\n\t\t8、时间段购物信息\n\n");rn scanf("%d",&op);rn while(op>8||op<1)rn rn printf("错误,请输入数字1到8");rn printf("\n\t\t 请输入操作:\n\t\t1、添加记录\n\t\t2、修改\n\t\t3、删除\n\t\t4、查询\n\t\t5、统计\n\t\t6、会员\n\t\t7、额购物\n\t\t8、时间段购物信息\n\n");rn scanf("%d",&op);rn rn read();rn if(op==1)rn add();rn else if(op==2)rn update();rn else if(op==3)rn del();rn else if(op==4)rn query_fruit();rn else if(op==5)rn show();rn else if(op==6)rn query_vip();rn else if(op==7)rn query_big_info();rn else if(op==8)rn query_time();rn save();rn return 0;rn

续2

01-27

//population.hrnrn#include"chrom.h"rn//#includernrn//const int rnconst int POPSIZE=7;rnconst int SAMPLESIZE=10;rnrnconst char* SAMPLE_FILE="..\\..\\sample.txt";rnconst char* SAMPLE_RESULT_FILE="..\\..\\sample_result.txt";rn//const char* OLDGEN_FILE="..\\..\\oldgen.txt";rn//const char* NEWGEN_FILE="..\\..\\newgen.txt";rnrnifstream sample_file(SAMPLE_FILE);rnifstream sample_result_file(SAMPLE_RESULT_FILE);rn//fstream oldgen_file(OLDGEN_FILE);rn//fstream newgen_file(NEWGEN_FILE);rnrndouble sample[SAMPLESIZE];rndouble sample_result[SAMPLESIZE];rn//string oldgen[POPSIZE];rn//string newgen[POPSIZE];rnrnrnvoid ReadSample() //to arraysrn string s;rnrn if(!sample_file || !sample_result_file) rn cout<<"NO sample FILE(s)!";rn exit(0);rn rn for(int i=0; i>sample[i];rn cout<>sample_result[i];rn rn//ReadSample()rnrnrnrnrnrnrnrnrnrnrnrnconst int SUMRATE=7;rnrnclass Poprnpublic:rn string the_strings[POPSIZE];rn double result[POPSIZE];rn static int RATE1R;rn static int RATE2R;rn static int RATEGR;rn Chrom chroms[POPSIZE];rnrn Pop();rn Chrom* GetBody() return chroms;rn void Evaluate3(double v);rn static void CreateRRates(void);rn void Recombine1(void);rn void Recombine2(void);rn void RecombineGene(void);rn void Mutate(void);rnrn void CountFit (double error);rn void Scaling(double error);rn void printChroms(void); //test onlirn void ExchangeGene(int no1, int no2);rn;//class Poprnrnint Pop::RATE1R = 1;rnint Pop::RATE2R = 1;rnint Pop::RATEGR = 1;rnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnvoid Pop::Mutate() rn for(int i=0; ichroms [i].Mutate ();rn rnrnrnvoid Pop::Evaluate3(double v) rn for(int i=0; iEvaluate2(1);rn rnrnrnrnrnvoid Pop::CreateRRates(void) rn srand(unsigned(time(0)));rn while(Pop::RATE1R ==0 ||rn Pop::RATE2R ==0 ||rn Pop::RATEGR ==0) rn Pop::RATE1R = rand() % SUMRATE;rn Pop::RATE2R = rand() % SUMRATE;rn Pop::RATEGR = rn SUMRATE - Pop::RATE2R - Pop::RATEGR;rn rnrnrnrnrnvoid Pop::RecombineGene() rn int R = Pop::RATEGR;rn if(0 == R) rn cout<<"Recombination Rate not inited!";rn exit(0);rn rn else //T times Recombine1rn int no1=0; rn int no2=0;rn int T = R * POPSIZE / SUMRATE;rn rn// cout<ExchangeGene(no1,no2);rn rn rn rn//RecombineGene()rnrnrnrnrnvoid Pop::ExchangeGene(int n1, int n2) rnrn srand(unsigned(time(0)));rn int pos = rand() % GENE_NUMBER;rn cout<<"at gene "<chroms [n1].genes [pos].GetString();rn string s2=this->chroms [n2].genes [pos].GetString();rn cout<chroms [n1].the_string.substr rn (pos*GENELEN, GENELEN);rn s2+=this->chroms [n2].the_string.substr rn (pos*GENELEN, GENELEN);rn cout<chroms[n1] =Chrom(s1) ;rn// this->chroms[n2] =c1 ;rnrnrnrnrnPop::Pop() rn string cs="";rn string s="";rn srand((unsigned)time(0));rnrn for(int i=0; i HEADLEN-1)rn s += 'a';rn elsern s += CHARSET [rand() % CHARSETLEN];rn rn for(i=0; ichroms[i] = c;rn this->result[i]=0;rn this->the_strings[i]=cs;rn rnrnrnvoid Pop::Scaling(double error) rn this->CountFit (error);rn int max=0;rn for(int i=0; ichroms [i].CountFit rn (sample[i], sample_result[i], error)rn <<'\t';rn rn rnrnrnrnrnrnvoid Pop::printChroms(void) rn for(int i=0; ichroms [i].GetString ()rn <

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试