编辑:
以下是我能够进行的查询。。。一些什么。为了澄清,表中有多列,但需要查询其中的2列,但也需要作为单列。而且我真的想要我想要查询的2的相反列。如果列a=用户#,我希望数据在列b中,反之亦然。
下面是我所拥有的,它确实有效,但我有两个错误。
mysqli::stat():无法在/home/中获取mysqli。。。。。。。注意:unserialize():偏移处的错误
这是代码;
$db=$this->getDbo();$query=$db->getQuery(true);
// Select the required fields from the table.
$query->select('d.*, uida AS contact ');
$query->from('`#__user_memberlinks` AS d');
$query->where('d.uidb =' . $userID);
$query->where('d.usera = 1')->andWHERE ('d.userb = 1');
// Join over the users for the checked out user.
$query->select('uc.name AS uEditor');
$query->join('LEFT', '#__users AS uc ON uc.id=d.checked_out');
// Join over the created by field 'created_by'
$query->join('LEFT', '#__users AS created_by ON created_by.id = d.created_by');
// Join over the created by field 'modified_by'
$query->join('LEFT', '#__users AS modified_by ON modified_by.id = d.modified_by');
$db = $this->getDbo();
$query2 = $db->getQuery(true);
// Select the required fields from the table.
$query2->select('b.*, uidb AS contact');
$query2->from('`#__user_memberlinks` AS b');
$query2->where('b.uida =' . $userID);
$query2->where('b.usera = 1')->andWHERE ('b.userb = 1');
// Join over the users for the checked out user.
$query2->select('uc.name AS uEditor');
$query2->join('LEFT', '#__users AS uc ON uc.id= b.checked_out');
// Join over the created by field 'created_by'
$query2->join('LEFT', '#__users AS created_by ON created_by.id = b.created_by');
// Join over the created by field 'modified_by'
$query2->join('LEFT', '#__users AS modified_by ON modified_by.id = b.modified_by');
$query->union($query2);
谢谢
组织。为历史留下的帖子
我在一个表中有两列;
A列 | B列 | UA |
---|---|---|
111 | 222 | 1 |
222 | 333 | <1>|
222 | 444 | <1>|
111 | 333 | 1 | <1>
555 | 222 | <1>
您的基本方法应该是使数据变平,这样您就可以像对待普通查询一样对待它。您没有指定RDBMS,但这适用于SQL Server
--Set up sample data
;with cteTabA as (
SELECT * FROM ( VALUES
('111', '222', '1', '2')
, ('222', '333', '11', '21')
, ('222', '444', '12', '22')
, ('111', '333', '13', '33')
, ('555', '222', '14', '41')
) as TabA(ColA, ColB, UA, UB)
) SELECT *
INTO #Sample
FROM cteTabA
--SELECT * FROM #Sample --Display test data
--Set up what we're looking for
DECLARE @LookFor char(3) = '222';
--Solution - flatten the table, but log where the ID came from
with cteFlat as (
SELECT ColA as ID, UB as Opposite, 'A' as MatchCol
FROM #Sample
UNION ALL
SELECT ColB as ID, UA as Opposite, 'B' as MatchCol
FROM #Sample
)--Now just search for it
SELECT * FROM cteFlat as F
WHERE ID = @LookFor
--Clean up
DROP TABLE #Sample
输出:
ID | 对面 | MatchCol |
---|---|---|
222 | 21 | A|
222 | A | |
222 | 1 | B[/tr>|
222 | 14 | B[/tr>
跟进;
上述《工会守则》确实有效。
未序列化的错误是由Joomla的Debugging函数引起的,如果调试关闭,则不会显示在视图中。不确定原因,或者是否是问题,因为它确实正确地检索了数据。如果我理解正确的话,Joomla有一种处理未序列化数据的方法。
";mysqli::stat():无法在/home/中获取mysqli"错误,通过将服务器、数据库类型更改为MySQL(PDO)而消失。猜测MySQLi不能很好地处理联合查询。错误似乎来自库/jommla/database/driver/mysqli中的文件。。。
谢谢大家的帮助!