DELIMITER $$
USE `xxxxxx`$$
DROP PROCEDURE IF EXISTS `VIEW_GCELC_DELEGATE_SP`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `VIEW_GCELC_DELEGATE_SP`(
)
BEGIN
SELECT lc_data.indicode, lc_indi.lastname, lc_indi.firstname, lc_org.orgname
FROM tb_gcelc_data AS lc_data
INNER JOIN tb_gcelc_orgreg AS lc_org ON lc_data.orgcode = lc_org.orgcode
INNER JOIN tb_gcelc_indireg AS lc_indi ON lc_data.orgcode = lc_indi.orgcode
WHERE lc_data.year = YEAR(CURDATE())
ORDER BY lc_org.orgname;
END$$
DELIMITER ;
这是输出:
indicode lastname firstname orgname
379257 Testing Testing Company Number One
957914 Testing Testing Company Number One
729065 Testing Testing Company Number One
389915 Testing Testing Company Number One
652854 Testing Testing Company Number One
696817 Testing Testing Company Number One
469712 Testing Testing Company Number One
450179 Testing Testing Company Number One
966966 Testing Testing Company Number One
379257 Test Mode Testing Again Company Number One
957914 Test Mode Testing Again Company Number One
729065 Test Mode Testing Again Company Number One
389915 Test Mode Testing Again Company Number One
652854 Test Mode Testing Again Company Number One
696817 Test Mode Testing Again Company Number One
469712 Test Mode Testing Again Company Number One
450179 Test Mode Testing Again Company Number One
966966 Test Mode Testing Again Company Number One
379257 More Test More Company Number One
957914 More Test More Company Number One
729065 More Test More Company Number One
389915 More Test More Company Number One
652854 More Test More Company Number One
696817 More Test More Company Number One
469712 More Test More Company Number One
450179 More Test More Company Number One
966966 More Test More Company Number One
由于循环输出,这很奇怪。
提前谢谢!
答案 0 :(得分:0)
感谢所有回复的人。无论如何,我终于解决了我的问题。我只是分析为什么我会得到多个Orgname,因为这个:
INNER JOIN tb_gcelc_indireg AS lc_indi ON lc_data.orgcode = lc_indi.orgcode
我将其更改为
LEFT JOIN tb_gcelc_indireg AS lc_indi ON lc_data.indicode = lc_indi.indicode
有!我的问题现在已经解决了。再次感谢你。