亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

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

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

問(wèn)題描述

問(wèn)題解答

回答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)文章:
主站蜘蛛池模板: 国产乱码亚洲精品一区二区 | 免费视频久久看 | 毛片大全高清免费 | va免费视频 | 日韩欧美毛片免费看播放 | 妞干网在线观看视频 | 在线观看免费视频一区 | 久碰香蕉精品视频在线观看 | 免费在线亚洲 | 色婷婷色综合激情国产日韩 | 欧美精品亚洲网站 | 国内自拍区 | 欧美男女爱爱视频 | 久久综合九色综合亚洲小说 | 日本久色 | 国产91中文剧情在线观看 | 中国一级特黄的片子免费 | 91播放在线 | 亚洲图片二区 | 高清视频一区 | 日日草夜夜操 | 一区二区精品在线观看 | 亚洲综合在线最大成人 | 国产精品黄 | 黄色视频毛片 | 国产成人啪精品午夜在线播放 | 曰本一级毛片免费 | 国产色婷婷视频在线观看 | 国产成人精品日本亚洲18图 | 美女福利视频一区 | 国产最强大片免费视频 | 成人欧美一区二区三区小说 | 不卡久久| 久久精品日本免费线 | 老头做爰xxxx视频 | 成年男女男免费视频网站不卡 | 欧美特黄a级高清免费看片 欧美特黄a级猛片a级 | 影音先锋ady69色资源网站 | 美女18一级毛片免费看 | 成人看片黄a免费看视频 | 成人美女免费网站视频 |