1.簡單的demo語句進行報表統計
2.基於簡單的demo語句進行公升級
1.sql語句
set foreign_key_checks=0;
-- ----------------------------
-- table structure for test
-- ----------------------------
drop table if exists `test`;
create table `test` (
`fid` int(10) default null,
`fname` varchar(10) default null
) engine=innodb default charset=utf8;
-- ----------------------------
-- records of test
-- ----------------------------
insert into `test` values ('1', '登入');
insert into `test` values ('1', '註冊');
insert into `test` values ('1', '退出');
insert into `test` values ('2', '登入');
insert into `test` values ('2', '註冊');
insert into `test` values ('2', '退出');
insert into `test` values ('2', '修改');
insert into `test` values ('3', '登入');
insert into `test` values ('3', '註冊');
insert into `test` values ('3', '退出');
insert into `test` values ('3', '修改');
insert into `test` values ('3', '司機');
2.效果圖如下:
效果圖.png
3.操作語句
select
distinct oo.fname "功能",
if(isnull(aa.fname),null,'√') '免費版',
if(isnull(bb.fname),null,'√') '標準版',
if(isnull(cc.fname),null,'√') '旗艦版'
from
test oo
left join
test aa
on oo.fname = aa.fname and aa.fid = 1
left join
test bb
on oo.fname = bb.fname and bb.fid = 2
left join
test cc
on oo.fname = cc.fname and cc.fid = 3
order by aa.fname desc,bb.fname desc,cc.fname desc
1.sql語句:
2.效果圖:
效果圖2.png
3.操作語句
select
distinct menu.m_name "功能",
if(isnull(menu1.m_name),null,'√') '免費版',
if(isnull(menu2.m_name),null,'√') '標準版',
if(isnull(menu3.m_name),null,'√') '旗艦版'
from
c_menu menu
left join
(select
c_menu.m_name
from
c_menu
where
c_menu.m_sequence
in (select
c_rm.m_sequence
from
c_rm
where
c_rm.ro_sequence in (select
c_role.ro_sequence
from
c_role
where
c_role.tempversion = 1))) menu1
on menu.m_name = menu1.m_name
left join
(select
c_menu.m_name
from
c_menu
where
c_menu.m_sequence
in (select
c_rm.m_sequence
from
c_rm
where
c_rm.ro_sequence in (select
c_role.ro_sequence
from
c_role
where
c_role.tempversion = 2))) menu2
on menu.m_name = menu2.m_name
left join
(select
c_menu.m_name
from
c_menu
where
c_menu.m_sequence
in (select
c_rm.m_sequence
from
c_rm
where
c_rm.ro_sequence in (select
c_role.ro_sequence
from
c_role
where
c_role.tempversion = 3))) menu3
on menu.m_name = menu3.m_name
where
menu.m_sequence
in (select
c_rm.m_sequence
from
c_rm
where
c_rm.ro_sequence in (select
c_role.ro_sequence
from
c_role
where
c_role.tempversion is not null))
4.分析:
建立第乙個子查詢:找到所有tempversion=1的版本
select
c_role.ro_sequence
from
c_role
where
c_role.tempversion = 1
建立第二個子查詢:找到對應的m—sequence
select
c_rm.m_sequence
from
c_rm
where
c_rm.ro_sequence in (select
c_role.ro_sequence
from
c_role
where
c_role.tempversion = 1)
建立第三個子查詢:找到對應的m—name
select
c_menu.m_name
from
c_menu
where
c_menu.m_sequence
in (select
c_rm.m_sequence
from
c_rm
where
c_rm.ro_sequence in (select
c_role.ro_sequence
from
c_role
where
c_role.tempversion = 1))
你問我答001(mysql)
請說說你知道的集中mysql儲存引擎 至少3種 myisam,innodb,menory 請簡述什麼是資料庫,資料庫的特點是什麼?資料庫可以理解為用來管理和儲存的電子檔案櫃,資料庫的特點 1 持久化儲存資料的。其實資料庫就是乙個檔案系統 2 方便儲存和管理資料 請簡述什麼是sql structure...
mysql面試題及答案001 mysql的面試題
這是我寫的 select from select year,month,money from order sum a where exists select month from order sum b where b.year 2014 and a.month b.month group by m...
mysql查詢訂單年月周報表查詢
只需要把訂單簽收時間擷取為年,where條件判斷為今年,在把訂單簽收時間擷取為月根據月分組,sum 訂單 這樣子就可以查詢出一年中每個月的訂單金額 和查詢年訂單差不多,擷取簽收時間為月周,在根據簽收時間擷取為周天,分組就可以了 omsumamountactuallypaid為訂單金額 omrecei...