sql,SELECT * FROM dede_archives WHERE channel = 频道ID ORDER BY pubdate DESC,
`,,2. 获取文章详情:,
`sql,SELECT * FROM dede_archives WHERE id = 文章ID,
`,,3. 获取栏目列表:,
`sql,SELECT * FROM dede_channel WHERE parentid = 0,
`,,4. 获取子栏目列表:,
`sql,SELECT * FROM dede_channel WHERE parentid = 父栏目ID,
`,,5. 获取标签列表:,
`sql,SELECT * FROM dede_taglist,
`,,6. 获取指定标签的文章列表:,
`sql,SELECT * FROM dede_archives WHERE tag = '标签名称',
“在Dedecms(织梦内容管理系统)中,SQL语句是用于从数据库中调用和修改数据的重要工具,以下是一些常用的Dedecms SQL语句汇总:
功能型SQL语句
1、添加自定义属性
INSERT INTO dede_arcatt (sortid, att, attname) VALUES (9, 'd', '评论');
ALTER TABLE dede_archives MODIFY flag SET ('c','h','p','f','s','j','a','b','d') DEFAULT NULL;
2、批量为作者和来源赋值
UPDATE dede_archives SET writer='要赋的值' WHERE writer='';
UPDATE dede_archives SET source='要赋的值' WHERE source='';
3、删除指定IP的评论
DELETE FROM dede_feedback WHERE dede_feedback.ip = '000.000.000.000';
4、清空文章中关键字字段
UPDATE dede_archives SET keywords='';
5、批量替换发布时间、入库时间、更新时间
第一步:在后台新增一个文章,得到一个时间戳,比如20090113 14:13:32。
第二步:执行以下SQL语句进行替换。
UPDATE dede_archives SET sortrank = 1231846313;
UPDATE dede_archives SET senddate = 1231846313;
UPDATE dede_archives SET pubdate = 1231846313;
6、批量修改栏目为动态或者静态
UPDATE dede_arctype SET isdefault = '1';
// 动态
UPDATE dede_arctype SET isdefault = '1';
// 静态
7、批量替换
UPDATE dede_addonarticle SET body=REPLACE(body, '论坛', '社区') WHERE body LIKE "%论坛%";
数据调用型SQL语句
1、统计代码
SELECT count(*) as c FROM dede_archives WHERE channel=1; // 共有文章数 SELECT count(*) as c FROM dede_archives WHERE channel=2; // 共有图集数 SELECT count(*) as c FROM dede_archives WHERE channel=3; // 共有软件数 SELECT count(*) as c FROM dede_feedback; // 共有评论数 SELECT count(mid) as c FROM dede_member ; // 共有会员数 SELECT sum(click) as c FROM dede_archives; // 文章阅读人次 SELECT count(*) as c FROM dede_archives WHERE pubdate > UNIX_TIMESTAMP(CURDATE()); // 今日更新文章数
2、调用特定会员发布的文章内容
SELECT * FROM dede_archives WHERE mid=1;
3、调用Discuz论坛附件带图片的帖子
SELECT cdb_p_w_uploads.aid, cdb_p_w_uploads.p_w_upload, cdb_threads.tid, cdb_threads.fid, cdb_threads.subject FROM cdb_p_w_uploads LEFT JOIN cdb_threads ON cdb_threads.tid = cdb_p_w_uploads.tid WHERE cdb_p_w_uploads.readperm = '0' AND displayorder >= '0' AND filetype = 'p_w_picpath/pjpeg' GROUP BY tid LIMIT 0,2;
4、调用UCHOME最新日志
SELECT subject, viewnum, blogid, uid FROM uchome_blog ORDER BY blogid DESC LIMIT 0,8;
5、会员积分排行
SELECT mid, userid, uname, scores FROM dede_member ORDER BY scores DESC LIMIT 0,10;
6、企业最新产品调用方法(图片+标题)
SELECT a.id, a.litpic, a.title FROM dede_addonshop p LEFT JOIN dede_archives a ON a.id = p.aid ORDER BY a.id DESC LIMIT 0,4;
7、调用最新加入企业及企业所属行业代码到首页
SELECT m.mid, m.mtype, m.userid, m.matt, c.mid, c.company, c.comface, d.ename, d.evalue, d.egroup FROM dede_sys_enum AS d, dede_member AS m LEFT JOIN dede_member_company AS c ON c.mid = m.mid WHERE m.mtype ='企业' AND m.matt = 1 AND c.vocation = d.evalue AND d.egroup ='vocation' LIMIT 0,10;
8、推荐会员(带用户头像)
SELECT u.username, u.userid, u.uface FROM dede_member AS u LEFT JOIN dede_space AS e ON e.spacemod='avatar' AND e.itemid=u.userid WHERE u.spacemod='avatar' AND e.itemid=u.userid ORDER BY RAND() LIMIT 0,10;
FAQs(相关问题解答)
1、如何备份数据库?
答:在进行任何SQL操作之前,务必先备份数据库,可以通过phpMyAdmin等工具导出数据库文件,或者使用命令行工具mysqldump进行备份。
mysqldump u [username] p[password] [database_name] > backup.sql
2、如何恢复数据库?
答:如果需要恢复数据库,可以使用mysql命令导入备份文件。
mysql u [username] p[password] [database_name] < backup.sql
通过以上SQL语句,你可以更加高效地管理和调用DedeCMS系统中的数据,确保在操作前做好数据备份,以免因误操作导致数据丢失。
原创文章,作者:未希,如若转载,请注明出处:https://www.kdun.com/ask/1218075.html
本网站发布或转载的文章及图片均来自网络,其原创性以及文中表达的观点和判断不代表本网站。如有问题,请联系客服处理。
发表回复