关键字

时间:2015-11-30 09:37:00

标签: php mysql sql

这是我的查询

$qry="select * from table where colnam in ($int1, $int2)";

colname值可以是1,4,3,2

例如

if $int1=2;

我想选择1, 2 and 3

if $int1=3;

我想选择2, 3 and 4

有可能吗?

4 个答案:

答案 0 :(得分:2)

将查询重写为:

$qry="select * from table where colnam BETWEEN $int1-- AND $int1++ ";

根本不需要$ int2。只需在2 or 3中分配值$int1

答案 1 :(得分:1)

使用此代码:

$col= ($int1-1).",".($int1).",".($int1+1);

$qry="select * from table where colnam in ($col)";

答案 2 :(得分:0)

Sub SomeSub()
Dim r As Long
Dim LastRow As Long

With ActiveSheet.UsedRange
    'Getting the last Row of the used range
    LastRow = .Rows(.Rows.Count).Row - 1
End With

'Loop for the rows of data
For r = 5 To LastRow

    'Quarter Calculation
    'Quarter 1
    Range("D" & r).Value = Application.WorksheetFunction.Sum(Range("A" & r), Range("B" & r), Range("C" & r))
    'Quarter 2
    Range("H" & r).Value = Application.WorksheetFunction.Sum(Range("E" & r), Range("F" & r), Range("G" & r))
    'Quarter 3
    Range("Q" & r).Value = Application.WorksheetFunction.Sum(Range("J" & r), Range("K" & r), Range("K" & r))
    'Quarter 4
    Range("M" & r).Value = Application.WorksheetFunction.Sum(Range("N" & r), Range("O" & r), Range("P" & r))

    'Bi Annual Calculation
    'First 6 Months
    Range("I" & r).Value = Application.WorksheetFunction.Sum(Range("A" & r), Range("B" & r), Range("C" & r), _
                                                             Range("E" & r), Range("F" & r), Range("G" & r))
    'Second 6 Months
    Range("R" & r).Value = Application.WorksheetFunction.Sum(Range("J" & r), Range("K" & r), Range("K" & r), _
                                                             Range("N" & r), Range("O" & r), Range("P" & r))

    'Year Calculation
    Range("S" & r).Value = Application.WorksheetFunction.Sum(Range("A" & r), Range("B" & r), Range("C" & r), _
                                                             Range("E" & r), Range("F" & r), Range("G" & r), _
                                                             Range("J" & r), Range("K" & r), Range("K" & r), _
                                                             Range("N" & r), Range("O" & r), Range("P" & r))

Next


End Sub

答案 3 :(得分:0)

在sql查询里面你不能这样写条件 使用以下代码查询,

if($int1 == 2){
  $int1 = 1,2,3;
}
elseif($int1 == 3){
  $int1 = 2,3,4;
}

然后执行查询,

$qry="select * from table where colnam in ($int1, $int2)";