我有一个非常复杂的查询,我已经加入了很多表格来查看
是的报告
我终于有了一个视图report_final
当我这样查询时
SELECT * FROM `reports_final` LIMIT 0,30
我得到的结果,但是当我这样给出时
SELECT count(*) FROM `reports_final`
或
SELECT count(1) FROM `reports_final`
或
SELECT SQL_CALC_FOUND_ROWS * FROM `reports_final` LIMIT 0,30
为了使用
SELECT FOUND_ROWS()
查询挂起!
db optimization and restructuring
我知道你会说
但是在这个时间表中这是不可能的
修改
表格结构
NULLDATA PAIDDATA nousers paidstatus payment_userid payment_date endtime name
这些是这里的领域
实际上这些是被操纵的列说通过做各种if循环和switch case 比如啄掉所需的柱子。所以,我在问是否有任何进一步的相关方法可以获得计数。
好的我会发布查询
CREATE VIEW `report_final` AS
select sql_big_result
`a`.`NULLDATA` AS `NULLDATA`,`a`.`PAIDDATA` AS `PAIDDATA`,
`a`.`nousers` AS `nousers`,
`a`.`paidstatus` AS `paidstatus`,`a`.`payment_userid`,`a`.`payment_date`,
date(`b`.`endtime`) AS `endtime`,
concat_ws(' ',`um`.`user_fname`,`um`.`user_lname`) AS `name`,
`um`.`user_email` AS `user_email`,
(case `um`.`user_gender` when 0 then 'MALE' else 'FEMALE' end) AS `gender`,
`um`.`user_dob` AS `user_dob`,`um`.`user_country` AS ,`um`.`user_language` ,
`um`.`user_doj` AS `user_doj`,
if(
(`c`.`payment_amount` is not null),
if(
(`c`.`payment_amount` < 9.91),
if(
(`c`.`payment_amount` not in (7.9,9.9)),'DISCOUNT','NORMAL'
),'GIFTCODE'
),
if(isnull(`b`.`endtime`),'REGISTER','FREE WORK')
) AS `type`,
`c`.`payment_amount`,`bm`.`brand_name` AS `brand_name`,`bu`.`brand_master_id`,
`disc`.`discount_code` AS `discount_code`,`sp`.`programs_id` AS `programs_id`
from
`report1` `a`
left join `report2` `b` on `a`.`payment_userid` = `b`.`user_id`
left join `report3` `c` on `a`.`payment_userid` = `c`.`payment_userid`
join `user_master` `um` on (
`um`.`user_id` = `a`.`payment_userid`
and `um`.`user_id` NOT IN(0,1,'NULL','')
and `um`.`user_type` = 1
)
left join `brand_user` `bu` on `bu`.`user_id` = `um`.`user_id`
left join `brand_master` `b` on `bu`.`brand_master_id`=`b`.`brand_master_id`
left join `disc_net` `disc` on `disc`.`user_id` = `um`.`user_id`
left join `sub_prog` `sp` on `sp`.`user_id` = `um`.`user_id`
N.B
report1,report2,report3
是 mysql VIEWS