亚洲免费在线视频-亚洲啊v-久久免费精品视频-国产精品va-看片地址-成人在线视频网

您的位置:首頁技術(shù)文章
文章詳情頁

mysql - 數(shù)據(jù)庫JOIN查詢

瀏覽:126日期:2022-06-13 17:56:36

問題描述

問題解答

回答1:

drop table if exists article;drop table if exists category;drop table if exists r_ac;create table article(id serial not null,title varchar(100),expire timestamp,primary key(id));create table category(id serial not null,name varchar(50),primary key(id));create table r_ac(article int not null,category int not null,primary key(article, category));insert into article(title, expire) values (’a’, ’2017-05-20’),(’b’, null),(’c’, ’2017-03-04’),(’d’, ’2017-02-23’),(’e’, ’2017-04-23’),(’f’, ’2016-09-15’),(’g’, ’2017-06-09’);insert into category(name) values (’c1’),(’c2’),(’c3’),(’c4’),(’c5’),(’c6’),(’c7’);insert into r_ac (article, category) values(1, 1), (1, 2), (1, 5), (1, 7),(2, 1), (2, 6),(3, 5),(4, 1), (4, 4),(7, 1), (7, 7);select category, c.name, count(1) as c from r_ac as acinner join (select id, title, expire from article where expire is null or expire>now()) as z on ac.article=z.idleft join category as c on ac.category=c.idgroup by category, c.name;回答2:

select c.id,count(a.id) from category c LEFT JOIN r_ac r on r.category=c.idLEFT JOIN article a on a.id=r.article and ifnull(a.expire>NOW(),1)GROUP BY c.id

相關(guān)文章:
主站蜘蛛池模板: 韩国欧洲一级毛片免费 | 男女超猛烈啪啦啦的免费视频 | se视频在线观看 | 亚洲国产日韩欧美高清片a 亚洲国产日韩欧美在线 | 久草网站在线 | 国内精品久久久久影院亚洲 | 久久精品一区二区三区日韩 | 色本| 欧美日韩一级黄色片 | 亚洲欧美一区二区三区在线播放 | 中文字幕在线乱码不卡区区 | 亚洲精品国产第一区第二区国 | 亚洲精品国产成人99久久 | 伊人久久青草青青综合 | 欧美精品在欧美一区二区 | 俄罗斯一级毛片免费播放 | 久草视频免费在线播放 | 亚洲爆爽| 一区二区三区国模大胆 | 国产美女视频做爰 | 欧美一线不卡在线播放 | 美女黄色一级片 | 国产亚洲精品2021自在线 | 神马国产| 欧美大尺度aaa级毛片 | 全部免费的毛片在线看美国 | 欧美日韩一区二区三区在线观看 | 成人欧美视频在线看免费 | 欧美一区二区在线观看免费网站 | 久久亚洲人成国产精品 | 毛片网站免费在线观看 | 永久免费毛片在线播放 | 欧美yyy| 国内国外精品一区二区 | 手机看片日韩国产 | 国产三级全黄 | 日韩不卡在线 | 日韩一级大片 | 久草综合网 | 最新久久免费视频 | 女性无套免费网站在线看 |