-1

我需要一个小的修复查询请帮助我,没有修复。请参阅底部,我的示例代码,感谢所有帮助者..

ny_xd_satilanlar database rows
id---uyid---toplam---sipno
01---16---1---1237777777
02---30---3---1301275922
03---30---2---1301741801
04---11---4---1123467988


//NOT WORK RETURN : 0 (zero)
$total_urun = mysql_fetch_array(mysql_query("SELECT SUM(adet) as toplam FROM ny_xd_satilanlar WHERE sipno IN ('{$curTel['sipnolar']}') AND uid='{$urunid}'"));
$total_urun = $total_urun[toplam];

// EXAMPLE 1 = NOT WORK RETURN : 0 (zero)  HOW TO FİX QUERY ????
SELECT SUM(adet) as toplam FROM ny_xd_satilanlar WHERE sipno IN ('1237777777,1301275922,1301741801') AND uid='30'

// EXAMPLE 2 = NOT WORKİNG TRUE RETURN : 3 (three)  HOW TO FİX QUERY ????
SELECT SUM(adet) as toplam FROM ny_xd_satilanlar WHERE sipno IN ('1301275922,1301741801') AND uid='30'

// EXAMPLE 1 ALTERNATİVE QUERY = OK WORK RETURN 3+2= :5 (five) 
SELECT SUM(adet) as toplam FROM ny_xd_satilanlar WHERE (sipno='1237777777' OR sipno='1301275922' OR sipno='1301741801') AND uid='30'

需要修复第二个查询??

4

2 回答 2

1

您需要分隔这些IN值。目前,所有值都包含在 中',因此它们表现为单个值。除非正确转义,否则任何包含在引号中的内容都将被视为一个值。

SELECT SUM(adet) as toplam FROM ny_xd_satilanlar WHERE sipno IN (1237777777, 1301275922, 1301741801) AND uid='30'

SELECT SUM(adet) as toplam FROM ny_xd_satilanlar WHERE sipno IN (1301275922, 1301741801) AND uid='30'

或者,如果它们应该是字符串数字:

SELECT SUM(adet) as toplam FROM ny_xd_satilanlar WHERE sipno IN ('1237777777', '1301275922', '1301741801') AND uid='30'

SELECT SUM(adet) as toplam FROM ny_xd_satilanlar WHERE sipno IN ('1301275922', '1301741801') AND uid='30'
于 2013-06-16T10:20:20.870 回答
1

您需要IN使用单引号字符分隔您希望子句处理的值:

SELECT SUM(adet) as toplam FROM ny_xd_satilanlar WHERE sipno IN ('1237777777','1301275922','1301741801') AND uid='30';

SELECT SUM(adet) as toplam FROM ny_xd_satilanlar WHERE sipno IN ('1301275922','1301741801') AND uid='30';
于 2013-06-16T10:18:56.817 回答