English 中文(简体)
根据多重和高温条件重新分配多重记录
原标题:Retrieve multiple records based on multiple AND WHERE conditions

目前,我正面临一个问题,需要根据《家庭、社会、文化权利国际公约》的多重条款,从我的桌上收回多个记录。 每一《家庭福利法》条款都有两个条件。

<>可见>

+--------------+---------+------+-----+---------+----------------+
| Field        | Type    | Null | Key | Default | Extra          |
+--------------+---------+------+-----+---------+----------------+
| id           | int(11) | NO   | PRI | NULL    | auto_increment |
| entity_id    | int(11) | YES  | MUL | NULL    |                |
| attribute_id | int(11) | YES  |     | NULL    |                |
| value        | int(11) | YES  |     | NULL    |                |
+--------------+---------+------+-----+---------+----------------+

www.un.org/Depts/DGACM/index_spanish.htm 我需要检索:。

一种或多种记录将各种属性与相应的价值相匹配。 在此情况下,我有以下结构:

array(
   attribute => value,
   attribute => value,
   attribute => value
)

www.un.org/Depts/DGACM/index_spanish.htm 问题:

我无法通过阵列循环,为这一争执制定惠与义务条款,因为每一项惠与豁免条件都会自动取消。 所有归因/价值奶制品都应配对。

我几乎认为我有解决这一难题的办法:

SELECT `client_entity_int`. * 
FROM `client_entity_int` 
WHERE (attribute_id IN (1, 3)) 
HAVING (value IN ( 0 ,  3 ))

......但显然,如果我只需要把1归为0,将3归为3,那么,这将会恢复这两种特性的价值观。

希望得到任何帮助。

最佳回答

这种说法像对不同问题的看法一样。

SELECT ... WHERE ...
UNION
SELECT ... WHERE ...
UNION
SELECT ... WHERE ...
问题回答

如果你使用其他资源,则并非每个WHERE条款都会否定另一个条款:

例如:

WHERE (attribute_id = 1 and value =  0 )
OR    (attribute_id = 3 and value =  3 )

坚持所有条件均符合:

WHERE    (attribute_id = 1 and value =  0 )
OR       (attribute_id = 3 and value =  3 )
GROUP BY entity_id 
HAVING   COUNT(*) = 2

这项工作是:

SELECT `client_entity_int`. * 
FROM `client_entity_int` 
WHERE (attribute_id=1 AND value=0) OR (attribute_id=3 AND value=3)
...




相关问题
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 ...

热门标签