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 | 一级片在线视频 | 中文在线免费观看 | 日日操天天操 | 久久精品国产精品 | 国产精品欧美激情 | 成人羞羞国产免费 | 日韩色网站 | 特级黄色大片 | 国产一区二区在线播放 | 一区二区美女 | 在线免费观看黄色片 | 国产精品一区二 | 亚洲另类色图 | 国产不卡一区 | 青青草视频免费在线观看 | 黄色激情视频在线观看 | 色婷婷丁香 | www亚洲精品 | 国产黄视频在线观看 | 色综合欧美 | 欧美久久精品 | 国内自拍偷拍 | 97在线超碰 | 青青草手机在线视频 | 色婷婷国产| 日韩在线播放视频 | 五月婷视频 | 国产一区二区精品丝袜 | 天天拍天天干 | 一区二区三区不卡视频 | 亚洲福利网站 | 亚洲激情一区二区 | 少妇一级淫片免费观看 | 69免费视频 | 日本黄色视屏 | 天天干天天草 | 中国av在线播放 | 国产在线一区二区 |