是否还有其他sql子句在哪里?

时间:2015-05-05 05:00:23

标签: mysql

string1 = ["1.10","1.1","1.23","2.2","2.20"]
for x in string1:
    if x.find('0') > 0:
        place = string1.index(x)
        string1.remove(x)
        string1.insert(place+1, x)
print (string1)

在上面的SQL查询中,我想使用特定的SELECT tbl_tmpdtr.id, tbl_tmpdtr.userid, date(tbl_tmpdtr.in_out) as in_out, tbl_tmpdtr.status, tbl_employee.emp_id, tbl_employee.emp_lname, tbl_employee.emp_mname, tbl_employee.emp_fname FROM tbl_tmpdtr INNER JOIN tbl_employee ON tbl_tmpdtr.userid = tbl_employee.emp_id WHERE tbl_tmpdtr.in_out >= '2015-05-01' AND tbl_tmpdtr.in_out <= '2015-05-05' GROUP BY tbl_tmpdtr.userid 进行查询。但我已经使用了id子句。我该怎么做呢?或者你们有什么想法?还是任何方法?

3 个答案:

答案 0 :(得分:1)

如果我理解正确,这将对您有所帮助:

SELECT 
    tbl_tmpdtr.id, 
    tbl_tmpdtr.userid, 
    date(tbl_tmpdtr.in_out) as in_out, 
    tbl_tmpdtr.status, 
    tbl_employee.emp_id, 
    tbl_employee.emp_lname, 
    tbl_employee.emp_mname, 
    tbl_employee.emp_fname 
FROM tbl_tmpdtr 
INNER JOIN tbl_employee 
    ON tbl_tmpdtr.userid = tbl_employee.emp_id 
WHERE 
    tbl_tmpdtr.in_out >= '2015-05-01' 
    AND tbl_tmpdtr.in_out <= '2015-05-05' and tbl_tmpdtr.id=(specific id)
GROUP BY
    tbl_tmpdtr.userid

答案 1 :(得分:0)

您可以使用AND ON条款中的WHERE子句添加条件。

开启

SELECT 
    tbl_tmpdtr.id, 
    tbl_tmpdtr.userid, 
    date(tbl_tmpdtr.in_out) as in_out, 
    tbl_tmpdtr.status, 
    tbl_employee.emp_id, 
    tbl_employee.emp_lname, 
    tbl_employee.emp_mname, 
    tbl_employee.emp_fname 
FROM tbl_tmpdtr 
INNER JOIN tbl_employee 
    ON tbl_tmpdtr.userid = tbl_employee.emp_id 
      AND tbl_tmpdtr.id = {some id}
WHERE 
    tbl_tmpdtr.in_out >= '2015-05-01' 
    AND tbl_tmpdtr.in_out <= '2015-05-05'
GROUP BY
    tbl_tmpdtr.userid

<强> WHERE

SELECT 
    tbl_tmpdtr.id, 
    tbl_tmpdtr.userid, 
    date(tbl_tmpdtr.in_out) as in_out, 
    tbl_tmpdtr.status, 
    tbl_employee.emp_id, 
    tbl_employee.emp_lname, 
    tbl_employee.emp_mname, 
    tbl_employee.emp_fname 
FROM tbl_tmpdtr 
INNER JOIN tbl_employee 
    ON tbl_tmpdtr.userid = tbl_employee.emp_id 
WHERE 
    tbl_tmpdtr.in_out >= '2015-05-01' 
    AND tbl_tmpdtr.in_out <= '2015-05-05'
    AND tbl_tmpdtr.id = {some id}
GROUP BY
    tbl_tmpdtr.userid

答案 2 :(得分:0)

SELECT 
    tbl_tmpdtr.id, 
    tbl_tmpdtr.userid, 
    date(tbl_tmpdtr.in_out) as in_out, 
    tbl_tmpdtr.status, 
    tbl_employee.emp_id, 
    tbl_employee.emp_lname, 
    tbl_employee.emp_mname, 
    tbl_employee.emp_fname 
FROM tbl_tmpdtr 
INNER JOIN tbl_employee 
    ON tbl_tmpdtr.userid = tbl_employee.emp_id 
WHERE 
    tbl_tmpdtr.in_out between '2015-05-01' and  '2015-05-05' and tbl_tmpdtr.id=(specific id)
GROUP BY
    tbl_tmpdtr.userid