国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

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

mysql - 數據庫JOIN查詢

瀏覽:115日期: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国产乱子伦精品免 | 国内精品免费一区二区观看 | 国产成a人片在线观看视频 国产成版人视频网站免费下 | 在线综合视频 | 国产精品秒播无毒不卡 | 国产成人三级经典中文 | 美国一级片在线 | 久久爱噜噜噜噜久久久网 | 久久网视频 | 日韩久久影院 | 精品欧美日韩一区二区三区 | 欧美www| 国产欧美在线一区二区三区 | 色偷偷资源网 | 国产午夜精品理论片久久影视 | 欧美人在线 | 一级做a爰片久久毛片免费看 | 亚洲欧美日韩精品在线 | 久久精品亚洲乱码伦伦中文 | 毛片一区二区三区 | 欧美日韩一区二区在线观看 | 亚洲视频观看 | 免费在线观看毛片 | 久草视频福利在线 | 99精品小视频 | 成年毛片| 午夜91理论片 | 色偷偷亚洲女人天堂观看欧 | 亚洲视频 中文字幕 | 国产亚洲精品久久久久久久网站 | 成人午夜网 | 在线亚洲精品国产成人二区 | 男人干女人的视频 | 国产成人精品本亚洲 | 国产精品美女一区二区三区 | 久草a在线| 正在播放的国产a一片 | 久久久久久久久久综合情日本 | 在线欧美日韩精品一区二区 | 日本精品一区二区三区视频 |