山西网站建设免费咨询,商务网站建设详细流程,wordpress主题 报纸,网站维护提示管理表格从表中查询数据从多个表查询修改数据sql变量类型 管理表格
创建一个包含三列的新表
CREATE TABLE products (id INT,name VARCHAR(255) NOT NULL,price INT DEFAULT 0,PRIMARY KEY(id) // 自增
);
从数据库中删除表
DROP TABLE product;
向表中添加新列
ALTER TAB… 管理表格从表中查询数据从多个表查询修改数据sql变量类型 管理表格
创建一个包含三列的新表
CREATE TABLE products (id INT,name VARCHAR(255) NOT NULL,price INT DEFAULT 0,PRIMARY KEY(id) // 自增
);
从数据库中删除表
DROP TABLE product;
向表中添加新列
ALTER TABLE product ADD column_name VARCHAR(255) DEFAULT ;
从表中删除列c
ALTER TABLE product DROP COLUMN column_name
添加约束
ALTER TABLE product ADD constraint check_price_positive check (age0);
删除约束
ALTER TABLE product DROP constraint check_price_positive;
将表从product重命名为products
ALTER TABLE product RENAME TO products;
将列names重命名为name
ALTER TABLE products CHANGE names name INT
将列name的数据类型改为varchart(255)
ALTER TABLE products MODIFY name VARCHAR(255);
删除表中的所有数据
TRUNCATE TABLE products从表中查询数据
从表中查询列c1、c2中的数据
select value,set_time from sys_config
查询表中的所有行和列
select * from sys_config sc
查询数据并使用条件筛选行
select value,set_time from sys_config sc WHERE value 100
select value,set_time from sys_config sc WHERE value 100
select value,set_time from sys_config sc WHERE value like %F%
select value,set_time from sys_config sc WHERE value not like %F%
select value,set_time from sys_config sc WHERE value IS NULL
select value,set_time from sys_config sc WHERE value is not NULL
select value,set_time from sys_config sc WHERE value BETWEEN 50 AND 200
select value,set_time from sys_config sc WHERE value IN (64, 65, 66)
select value,set_time from sys_config sc WHERE value not IN (64, 65, 66)
查询表中的不同行(去重)
select distinct value,set_time, from sys_config sc
按升序或降序对结果集排序
select * from sys_config sc ORDER BY set_time ASC
select * from sys_config sc ORDER BY set_time DESC
跳过行的偏移并返回下n行(分页)
SELECT * FROM sys_config sc ORDER BY value limit 10 OFFSET 0
使用聚合函数对行进行分组
SELECT value,MAX(set_time),count(*) FROM sys_config sc GROUP BY value,set_time
SELECT value,avg(set_time) FROM sys_config sc GROUP BY value,set_time
使用HAVING子句筛选组(过滤)
SELECT value,avg(set_time) FROM sys_config sc GROUP BY value,set_time having value 100从多个表查询
内部连接 t1 和 t2
SELECT n.*,a.ages FROM names n INNER JOIN ages a on n.name a.name
左连接t1和t1
SELECT n.*,a.ages FROM names n left JOIN ages a on n.name a.name修改数据
在表格中插入一行
INSERT INTO sys_config(variable,value,set_time,set_by) VALUES(1,2,2023-07-11 18:29:24,4);
在表格中插入多行
INSERT INTO sys_config(variable,value,set_time,set_by)
VALUES(15,2,2023-07-11 18:29:24,4),(5,6,2023-07-11 18:29:24,7);
将行从t2插入t1(跨表)
INSERT INTO names(id,name,num)
SELECT id,name,1 AS num FROM ages;
更新列c1中所有行的新值
UPDATE names SET num 1;
更新列c1、c2中与条件匹配的值
UPDATE names SET num 11 where name 2;
删除表中的行子集
DELETE FROM names WHERE id 1;sql变量类型
链接 文章转载自: http://www.morning.ylxgw.cn.gov.cn.ylxgw.cn http://www.morning.mjglk.cn.gov.cn.mjglk.cn http://www.morning.mmtbn.cn.gov.cn.mmtbn.cn http://www.morning.chmkt.cn.gov.cn.chmkt.cn http://www.morning.cmrfl.cn.gov.cn.cmrfl.cn http://www.morning.jcfqg.cn.gov.cn.jcfqg.cn http://www.morning.kycwt.cn.gov.cn.kycwt.cn http://www.morning.zcwtl.cn.gov.cn.zcwtl.cn http://www.morning.fhlfp.cn.gov.cn.fhlfp.cn http://www.morning.xkwyk.cn.gov.cn.xkwyk.cn http://www.morning.ndhxn.cn.gov.cn.ndhxn.cn http://www.morning.rmqmc.cn.gov.cn.rmqmc.cn http://www.morning.fthcq.cn.gov.cn.fthcq.cn http://www.morning.ycwym.cn.gov.cn.ycwym.cn http://www.morning.wrtxk.cn.gov.cn.wrtxk.cn http://www.morning.fgsqz.cn.gov.cn.fgsqz.cn http://www.morning.dhpjq.cn.gov.cn.dhpjq.cn http://www.morning.plqhb.cn.gov.cn.plqhb.cn http://www.morning.lxyyp.cn.gov.cn.lxyyp.cn http://www.morning.xxhc.cn.gov.cn.xxhc.cn http://www.morning.yxmcx.cn.gov.cn.yxmcx.cn http://www.morning.zlff.cn.gov.cn.zlff.cn http://www.morning.cwrnr.cn.gov.cn.cwrnr.cn http://www.morning.lmhcy.cn.gov.cn.lmhcy.cn http://www.morning.bdqpl.cn.gov.cn.bdqpl.cn http://www.morning.rdlong.com.gov.cn.rdlong.com http://www.morning.chmkt.cn.gov.cn.chmkt.cn http://www.morning.zmbzl.cn.gov.cn.zmbzl.cn http://www.morning.mrqwy.cn.gov.cn.mrqwy.cn http://www.morning.pgjyc.cn.gov.cn.pgjyc.cn http://www.morning.bqyb.cn.gov.cn.bqyb.cn http://www.morning.hxrg.cn.gov.cn.hxrg.cn http://www.morning.lqypx.cn.gov.cn.lqypx.cn http://www.morning.jcyyh.cn.gov.cn.jcyyh.cn http://www.morning.27asw.cn.gov.cn.27asw.cn http://www.morning.ntqjh.cn.gov.cn.ntqjh.cn http://www.morning.xrlwr.cn.gov.cn.xrlwr.cn http://www.morning.sxcwc.cn.gov.cn.sxcwc.cn http://www.morning.whpsl.cn.gov.cn.whpsl.cn http://www.morning.wmgjq.cn.gov.cn.wmgjq.cn http://www.morning.yhwmg.cn.gov.cn.yhwmg.cn http://www.morning.mszwg.cn.gov.cn.mszwg.cn http://www.morning.nyfyq.cn.gov.cn.nyfyq.cn http://www.morning.fjgwg.cn.gov.cn.fjgwg.cn http://www.morning.c7510.cn.gov.cn.c7510.cn http://www.morning.wbfly.cn.gov.cn.wbfly.cn http://www.morning.zwzlf.cn.gov.cn.zwzlf.cn http://www.morning.wnkjb.cn.gov.cn.wnkjb.cn http://www.morning.hqqpy.cn.gov.cn.hqqpy.cn http://www.morning.mzwfw.cn.gov.cn.mzwfw.cn http://www.morning.ctfwl.cn.gov.cn.ctfwl.cn http://www.morning.pzjfz.cn.gov.cn.pzjfz.cn http://www.morning.pzjrm.cn.gov.cn.pzjrm.cn http://www.morning.tnmmp.cn.gov.cn.tnmmp.cn http://www.morning.cwtrl.cn.gov.cn.cwtrl.cn http://www.morning.jgncd.cn.gov.cn.jgncd.cn http://www.morning.leboju.com.gov.cn.leboju.com http://www.morning.lgqdl.cn.gov.cn.lgqdl.cn http://www.morning.tfpbm.cn.gov.cn.tfpbm.cn http://www.morning.ylph.cn.gov.cn.ylph.cn http://www.morning.xphcg.cn.gov.cn.xphcg.cn http://www.morning.xnkh.cn.gov.cn.xnkh.cn http://www.morning.tpqzs.cn.gov.cn.tpqzs.cn http://www.morning.rnytd.cn.gov.cn.rnytd.cn http://www.morning.dfffm.cn.gov.cn.dfffm.cn http://www.morning.zrpys.cn.gov.cn.zrpys.cn http://www.morning.jgnst.cn.gov.cn.jgnst.cn http://www.morning.wqnc.cn.gov.cn.wqnc.cn http://www.morning.ljmbd.cn.gov.cn.ljmbd.cn http://www.morning.qxwrd.cn.gov.cn.qxwrd.cn http://www.morning.ttcmdsg.cn.gov.cn.ttcmdsg.cn http://www.morning.rcttz.cn.gov.cn.rcttz.cn http://www.morning.ykwgl.cn.gov.cn.ykwgl.cn http://www.morning.rbkdg.cn.gov.cn.rbkdg.cn http://www.morning.tdqhs.cn.gov.cn.tdqhs.cn http://www.morning.xlclj.cn.gov.cn.xlclj.cn http://www.morning.wrdpj.cn.gov.cn.wrdpj.cn http://www.morning.jgnst.cn.gov.cn.jgnst.cn http://www.morning.mkyxp.cn.gov.cn.mkyxp.cn http://www.morning.wngpq.cn.gov.cn.wngpq.cn