开发者

Selecting the highest salary

Assuming a wagetable:

name     lowhours  highhours  wage 
 Default  0.0       40.0       100  
 Default  40.0      50.0       150  
 Default  50.0      70.5       154  
 Default  70.5      100.0      200  
 Brian    0.0       40.0       200  
 Brian    40.0      50.0       250  
 Brian    50.0      60.0       275  
 Brian    60.0      70.0       300  
 Brian    70.0      80.0       325  
 Brian    80.0      9999.0     350  
 Chad     0.0       40.0       130  
 Chad     40.0      9999.0     170 

I am currently using this code (AutoIT scripting:

func getCurrentWage($Employee, $Hour_number)
    Dim  $row
    Local $Wage = 0
    Local $Found = "found"
    _SQLite_QuerySingleRow(-1, "SELECT wage FROM w开发者_StackOverflow中文版agetable WHERE name LIKE " & _SQLite_Escape($Employee) & " AND " & _SQLite_Escape($Hour_number) & " BETWEEN lowhours AND highhours;", $row)
    if @error then
        _SQLite_QuerySingleRow(-1, "SELECT wage FROM wagetable WHERE name LIKE 'Default' AND " & _SQLite_Escape($Hour_number) & " BETWEEN lowhours AND highhours;", $row)
        $Found = "not found"
    endif

    If ($row[0] == "") Then Msgbox(0,0,"Error getCurrentWage")
    $Wage = $row[0]

    Debug("Wage='" & $Wage & "'  because " &$Employee&" was "& $Found& " -- and Hours Elapsed is " & $Hour_number, true)
    return $Wage
EndFunc

So those 2 queries are perfect if the Hour_number is inbetween a low hour or a high hours. I need some sort of query where it will basically do something like:

SELECT wage from wagetable WHERE name LIKE $Employee AND max(highhours)

and then just repeat it for 'Default' is the employee is not found.

Extra: Is it possible to try the 'Default' if $Employee is not found with just 1 query?


Is it possible to try the 'Default' if $Employee is not found with just 1 query?

  SELECT name, wage, highhours
    FROM wagetable
   WHERE name like 'Brian' OR
         name like 'Default'
ORDER BY name,
         highhours desc

This query works when querying for Brian, but for it to work for any name the Default should be stored in your database starting with a special character _-+@, because numbers and letters come first in sorting.

Another way would be for you to create another column to the table, for the sake of our argument, called priority which should have the value 0 for Default and 1 for any other user. Then you could simply do:

  SELECT name, wage, highhours
    FROM wagetable
   WHERE name like 'Brian' OR
         name like 'Default'
ORDER BY priority desc,
         highhours desc

Of course it is the same solution, but it is a better approach, than relying on a special character in the name of the default values.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜