English 中文(简体)
加入两个表格,但合并的关键是进行扼杀。
原标题:Joining two tables but the join key is in a query string

我想加入这两个表格,但第二张表格的正文中正出现争执。

page_id     url
1           a
2           c
3           d

。 表格

system_id       query
1               page_id=1&content=on&image=on
2               type=post&page_id=2&content=on

您可以看到,<编码>网页_id是querystring in system table。

因此,我如何与他们一道采用以下标准加入表格方法?

SELECT*
FROM page AS p

LEFT JOIN system AS s
ON p.page_id = s.page_id

<>光线>

页: 1 引文如下:

system_id       page_id    query
1               1           page_id=1&content=on&image=on
2               2           type=post&page_id=2&content=on
3               NULL        type=page

但我不希望这样做的原因是,<编码>网页_id不需要很多记录。 我不想打一栏,上面有太多的<代码>null。

最佳回答

我猜想你们想要的是这样的东西(MSSQL!):


DECLARE @query VARCHAR(50)
DECLARE @Lenght INT  
DECLARE @PageID INT 

SET @query =  4kkhknmnkpage_id=231&content=on&image=on 
SET @Lenght = PATINDEX( %&% , substring(@query,PATINDEX( %page_id=% , @query),50)) - 9
SET @PageID = CAST(SUBSTRING(@query,PATINDEX( %page_id=% , @query) + 8,@Lenght) AS INT)

SELECT @PageID -- you can do as you please now :)

OR:

SELECT*
FROM page AS p
LEFT JOIN (SELECT CAST(SUBSTRING(query,PATINDEX( %page_id=% , query) + 8,(PATINDEX( %&% , substring(query,PATINDEX( %page_id=% , query),50)) - 9)) AS INT) AS page_id
                FROM system) AS s
ON p.page_id = s.page_id 

-- Do as you please again :) 

我猜想你真心想要的东西(MYSQL!):


SET @query :=  4kkhknmnkpage_id=231&content=on&image=on ;
SET @Lenght := POSITION( &  IN (SUBSTR(@query,POSITION( page_id=  IN @query),50))) - 9;
SET @PageID := CAST(SUBSTR(@query,POSITION( page_id=  IN @query) + 8,@Lenght) AS  SIGNED );

SELECT @PageID

www.un.org/Depts/DGACM/index_french.htm


SELECT*
FROM page AS p
LEFT JOIN (SELECT CAST(SUBSTR(query,POSITION( page_id=  IN query) + 8,(POSITION( &  IN (SUBSTR(query,POSITION( page_id=  IN query),50))) - 9)) AS  SIGNED) AS pageID
           FROM system) AS s
ON p.page_id = s.pageID 
问题回答

我肯定会设立以下栏目:page_id ,,image(并编制索引)。 然后,数据库将更加简便,并将更快地开展工作。

Joining two tables without the common field and data type, is fundamentally wrong IMO.

我建议你摘录<代码>_id,并在数据库中插入该编码,并使用正常的加入来实现你所寻求的东西。

like

+------------+-----------+---------+
| system_id  |  page_id  |  query  |
------------------------------------

这里是一刀子,请上页。

$query =  page_id=1&content=on&image=on ;
$queryParts = explode( & , $query);

$params = array();
foreach ($queryParts as $param) {
    $item = explode( = , $param);
    $params[$item[0]] = $item[1];
} 
$page_id = $parems[ page_id ];

然后,你可以加入并使用简单的加入书,以适当方式解决问题。


<>Update:

由于你能够把该表变成一个可行的计划。 你们坚决需要担心一些有空row的行.。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签