mysql 查询遇到的问题
有两个表,
我写了一个查询语句如下,我标红的地方既是出现问题的地方,我将person2这列去掉就能正常查询,加上person2这列就报[Err] 1222 - The used SELECT statements have a different number of columns错误,首先确定表1的person2和表2的customer_name格式是一样的,不晓得为什么?
select `g`.`id` AS `id`,1 AS `f_type`,`g`.`bank_account` AS `account`,-(`g`.`get_money`) AS `money`,`g`.`get_money_date` AS `money_date`,`g`.`becuse` AS `becuse`,`g`.`person` AS `person`,`g`.`person2` AS `person2`,`g`.`balance` AS `balance` from `get_money_log` `g` union all select `ba`.`id` AS `id`,2 AS `f_type`,`ba`.`account` AS `account`,`ba`.`receivable_money` AS `money`,`ba`.`income_date` AS `money_date`,`ba`.`note` AS `becuse`,`ba`.`income_customer` AS `person`,`ba`.`balance` AS `balance` from `business_accounts` `ba` union select `bs`.`id` AS `id`,3 AS `f_type`,`bs`.`account` AS `account`,-(`bs`.`pay_already_money`) AS `money`,`bs`.`pay_date` AS `money_date`,`bs`.`note` AS `becuse`,`bs`.`pay_person` AS `person`,`bs`.`customer_name` AS `person2`,`bs`.`balance` AS `balance` from `business_shoud` `bs`
我写了一个查询语句如下,我标红的地方既是出现问题的地方,我将person2这列去掉就能正常查询,加上person2这列就报[Err] 1222 - The used SELECT statements have a different number of columns错误,首先确定表1的person2和表2的customer_name格式是一样的,不晓得为什么?
select `g`.`id` AS `id`,1 AS `f_type`,`g`.`bank_account` AS `account`,-(`g`.`get_money`) AS `money`,`g`.`get_money_date` AS `money_date`,`g`.`becuse` AS `becuse`,`g`.`person` AS `person`,`g`.`person2` AS `person2`,`g`.`balance` AS `balance` from `get_money_log` `g` union all select `ba`.`id` AS `id`,2 AS `f_type`,`ba`.`account` AS `account`,`ba`.`receivable_money` AS `money`,`ba`.`income_date` AS `money_date`,`ba`.`note` AS `becuse`,`ba`.`income_customer` AS `person`,`ba`.`balance` AS `balance` from `business_accounts` `ba` union select `bs`.`id` AS `id`,3 AS `f_type`,`bs`.`account` AS `account`,-(`bs`.`pay_already_money`) AS `money`,`bs`.`pay_date` AS `money_date`,`bs`.`note` AS `becuse`,`bs`.`pay_person` AS `person`,`bs`.`customer_name` AS `person2`,`bs`.`balance` AS `balance` from `business_shoud` `bs`
...全文
相关推荐
解决MySQL中IN子查询会导致无法使用索引问题
主要介绍了MySQL中IN子查询会导致无法使用索引问题,文章给大家介绍了两种子查询的写法,需要的朋友可以参考下
mysql unique key在查询中的使用与相关问题
今天小编就为大家分享一篇关于mysql unique key在查询中的使用与相关问题,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
Mysql升级到5.7后遇到的group by查询问题解决
主要给大家介绍了关于Mysql升级到5.7后遇到的group by查询问题的解决方法,文中通过示例代码介绍的非常详细,对同样遇到这个问题的朋友们具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。
MYSQL随机抽取查询 MySQL Order By Rand()效率问题
要从tablename表中随机提取一条记录,大家一般的写法就是:SELECT * FROM tablename ORDER BY RAND() LIMIT 1。 但是,后来我查了一下MYSQL的官方手册,里面针对RAND()的提示大概意思就是,在ORDER BY从句里面不能使用RAND()函数,因为这样会导致数据列被多次扫描。但是在MYSQL 3.23版本中,仍然可以通过ORDER BY RAND()来实现随机。 但是真正测试一下才发现这样效率非常低。一个15万余条的库,查询5条数据,居然要8秒以上。查看官方手册,也说rand()放在ORDER BY 子句中会被执行多次,自然效率及很低。 代
解决MySql大数据Like查询慢的问题
MySql查询数据慢可以用用这个工具,瞬间提升Like查询效率


