SELECT * FROM
(
SELECT a.*, b.`match_time` FROM `bifen_index_change` AS a
LEFT JOIN bifen_matches AS b ON a.`match_id` = b.`id`
ORDER BY b.`match_time` DESC
) AS c
GROUP BY c.match_id, c.type
ORDER BY c.match_time DESC, c.match_id ASC, c.type ASC
复制代码
select first_name,title,salary,s.to_date
from employees e
inner join titles t on e.emp_no = t.emp_no
inner join salaries s on e.emp_no = s.emp_no
where e.emp_no = 10001
outerjoin(外连接):left join 、right join
innerjoin (内链接):join
复制代码
[root@iZ8vbbslxnnj3fheohrwncZ ~]# mysql -
SHOW VARIABLES LIKE '%datadir%'
复制代码
cmd
C:\Users\Administrator>d:
D:\>cd d:\wamp64\bin\mysql\mysql5.7.14\bin
D:\wamp\bin\mysql\mysql5.6.17\bin
d:\wamp64\bin\mysql\mysql5.7.14\bin> mysql -u root (-p)
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
多字段确定唯一索引,则md5建立一个字段wysy varchat(100)
$wysy = md5(hp_season_id.'_'.hp_team_selfid.'_'.'score_type_id)
basketball_hp_teamdata_season表复制一张新的basketball_teamdata_season表,结构和记录一样
CREATE TABLE `basketball_teamdata_season` LIKE `basketball_hp_teamdata_season`;
INSERT INTO `basketball_teamdata_season` SELECT * FROM `basketball_hp_teamdata_season`;
update `xinhu_crm_library` set `uniqueId`=replace(`uniqueId`,' ','');//清除news表中content字段中的空格
SELECT a.*, b.name FROM xinhu_reads a LEFT JOIN xinhu_admin b ON a.optid = b.id where a.`table`= 'threadedtree';
$data = Db::database($this->database)
->table("basket_ball_hupu_team_season_data")
->field('0+CAST(ptsavg AS CHAR) as ptsavg')
->select();
复制代码
$database = Env::get($this->database . ".database");
$sql = "select * from `{$database}`.{$this->table} where hp_team_selfid = {$hpTeamSelfId} order by shirt_number+0 asc";
$data = Db::query($sql);
复制代码
prize_money int 11 中奖金额 1=1分 100=1元
ALTER TABLE `show_ticket` ADD INDEX index_create_time(`create_time`);
使用`
TABLE `admin_op_log` ADD COLUMN `op_object_id`
复制代码
SELECT count(*) FROM `sdsq-sports-data`.`basketball_player` WHERE ID=1;
rename table `sdsq-sports-data`.`basketball_ls_events_copy1` to `sdsq-sports-data`.`basketball_ls_events`;
给admin_op_log表在字段op_object后添加一个op_object_id 字段备注为操作对象id,类型int11默认值0
ALTER TABLE `admin_op_log` ADD COLUMN `op_object_id` int(11) NOT NULL DEFAULT 0 COMMENT '操作对象id' AFTER `op_object`;
复制代码
ALTER TABLE `test_table` MODIFY `test_value`VARCHAR(10) NOT NULL DEFAULT '' COMMENT '字段注释';
ALTER TABLE test_table CHANGE test_value_old test_value_new VARCHAR(10) NOT NULL DEFAULT '' COMMENT '字段注释';
ALTER TABLE test_table DROP COLUMN test_value;
DELETE FROM lottery_history_forecast WHERE forecast_version='20200115' And lottery_id='fcsd'
UPDATE `admin` SET `password` = '9a47f30157a92ca673ab0cd5b1e948216848ad31' WHERE `id` = 19;
insert into banner_conf (name,code,size,is_del,sys) values('发现首页','app_findindex','710*280','0','sports');
update `banners` set `direction`='app_findindex' where `id`=16;
mysql>update mysql.user set host='%' where user='root';
mysql>flush privileges;
show global variables like "%datadir%";
SELECT * FROM user_oauth WHERE openid='15062703446';
UPDATE `article` SET `from` = REPLACE(`from`,'乐窝窝','OwenZhang');
UPDATE `article` SET `from` = REPLACE(`from`,NULL,'OwenZhang');
UPDATE article SET hot= (300 + RAND()*1000);
UPDATE `case` SET click= (240 + RAND()*580) where store_id = 739;
use jumeijia;
update tablename set A='B' where A='';
update `case` set description=title where description='';
height:auto !important;
替换为
height:auto !important;width: 100%;
use jumeijia;
UPDATE article_store SET cont = replace(cont, 'height:auto !important;', 'height:auto !important;width: 100%;') ;
$Article = D('article_store');
var_dump($Article->getLastSql());
die();
D:\jumjia\App\Lib\Action\Home\StoreAction.class.php:206:string 'SELECT * FROM `article_store` WHERE ( `id` = 1 ) LIMIT 1 ' (length=58)
复制代码
如果你只需要查询某个字段的值,还可以使用getField方法,例如:
$Form = M("Form");
// 更改title值
$Form->where('id=5')->setField('title','ThinkPHP');
复制代码
$User = M("User"); // 实例化User对象
$User->where('id=5')->setInc('score',3); // 用户的积分加3
$User->where('id=5')->setInc('score'); // 用户的积分加1
$User->where('id=5')->setDec('score',5); // 用户的积分减5
$User->where('id=5')->setDec('score'); // 用户的积分减1
删除数据很简单,只需要调用delete方法返回值是false则表示SQL出错,返回值如果为0表示没有删除任何数据。
$Form = M('Form');
$User->where('id=5')->delete(); // 删除id为5的用户数据
复制代码
动态查询
借助PHP5语言的特性,ThinkPHP实现了动态查询,核心模型的动态查询方法包括下面几种:
方法名
说明
举例
getBy
根据字段的值查询数据
例如,getByName,getByEmail
getFieldBy
根据字段查询并返回某个字段的值
例如,getFieldByName
1**、使用select方法** 当select方法的参数为false的时候select(false),表示不进行查询只是返回构建SQL,例如:
2、使用buildSql方法
subQuery=subQuery = subQuery=model->field('id,name')->table('tablename')->group('field')->where($where)->order('status')->buildSql();
调用buildSql方法后不会进行实际的查询操作,而只是生成该次查询的SQL语句(为了避免混淆,会在SQL两边加上括号),然后我们直接在后续的查询中直接调用。
复制代码
SELECT a.id,a.username,ag.name,a.password,a.gid,a.addtime,a.lastlogin,a.status FROM admin AS a,admin_group AS ag WHERE a.gid=ag.id;
复制代码
$Model = new Model();// 实例化一个model对象 没有对应任何数据表
$result =$Model->query("SELECT a.id,a.username,ag.name,a.password,a.gid,a.addtime,a.lastlogin,a.status FROM admin AS a,admin_group AS ag WHERE a.gid=ag.id");
复制代码