av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

mysql - 數據庫JOIN查詢

瀏覽:120日期: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

相關文章:
主站蜘蛛池模板: 亚洲精品视频免费观看 | 99视频在线观看免费 | 亚洲综合五月天婷婷丁香 | 一本色道久久综合亚洲精品小说 | 999精品视频| 免费在线观看黄色片 | 亚洲色网址 | 日韩毛片在线观看 | 久久福利视频导航 | 久久一区视频 | 黄av在线 | 免费av一区二区三区 | 国产精品6 | 三级黄色片网站 | 激情五月激情综合网 | 国产精品久久久久久久久免费桃花 | 色婷婷精品国产一区二区三区 | 一级做a爰片久久毛片潮喷 视频一二区 | 毛片在线观看视频 | 精品小视频 | 91久久奴性调教 | 日本福利在线 | 91中文在线 | 国产精品毛片一区视频播 | 青草视频网站 | 亚洲免费高清 | 国产女人18毛片水18精品 | 天堂中文在线视频 | a在线播放| 91成人在线 | 日本视频免费观看 | 国产色婷婷 | 羞羞的视频在线观看 | 中文字幕亚洲精品 | 国产高潮在线观看 | 午夜精品福利视频 | 欧美色偷偷 | 无套内谢的新婚少妇国语播放 | 国产成人精品一区二 | 国产一区中文字幕 | 超碰免费在线 |