-2

我已经通过嵌套在另一个 SELECT 中,然后使用 ASC 使用标准选择查询尝试了所有现有尝试,但是由于某种原因它无法在我的 JSCharts 中加载。我的代码工作正常,减去顺序:

SELECT `$tableName`.`$patient_idField` , `$tableDataName`.`$patient_idField` , `$tableDataName`.`$resultField` , `$tableName`.`$login_idField`
FROM `$tableName`
JOIN `$tableDataName` ON `$tableName`.`$patient_idField` = `$tableDataName`.`$patient_idField`
COLLATE utf8_general_ci
WHERE `$tableName`.`$login_idField` = $usssName
ORDER BY `$tableDataName`.id DESC LIMIT 10

这是重新订购的尝试,但未能加载:

SELECT * FROM (
SELECT `$tableName`.`$patient_idField` , `$tableDataName`.`$patient_idField` , `$tableDataName`.`$resultField` , `$tableName`.`$login_idField`
FROM `$tableName`
JOIN `$tableDataName` ON `$tableName`.`$patient_idField` = `$tableDataName`.`$patient_idField`
COLLATE utf8_general_ci
WHERE `$tableName`.`$login_idField` = $usssName
ORDER BY `$tableDataName`.id DESC LIMIT 10 ) AS `$tableName` JOIN `$tableDataName` ORDER by `$tableDataName`.id ASC

在没有 PHP 的情况下更新...

SELECT userlist.patient_id, results.patient_id, results.result, userlist.login_id
FROM userlist
JOIN results ON userlist.patient_id = results.patient_id
COLLATE utf8_general_ci
WHERE userlist.login_id = ####
ORDER BY results.id DESC
LIMIT 10 

现在,如果我对 ASC 执行此操作之外的任何操作,它会在patient_id.

有效的代码,供将来参考

SELECT  *
FROM (
SELECT userlist.patient_id, results.result, userlist.login_id, results.id
FROM userlist
  JOIN results ON userlist.patient_id = results.patient_id
COLLATE utf8_general_ci
WHERE userlist.login_id = ####
ORDER BY results.id DESC
LIMIT 10 ) temp
ORDER BY id

它涉及删除其中一个.patient_idon SELECT。

4

2 回答 2

2

嵌套在另一个选择中应该可以工作;它是怎么失败的?

就像是:

select tablenamepatientidfield, tabledatanamepatientidfield, resultfield, loginidfield from (
    SELECT
        `$tableDataName`.id,
        `$tableName`.`$patient_idField` AS tablenamepatientidfield,
        `$tableDataName`.`$patient_idField` AS tabledatanamepatientidfield,
        `$tableDataName`.`$resultField` AS resultfield,
        `$tableName`.`$login_idField` AS loginidfield,
    FROM `$tableName`
    JOIN `$tableDataName` ON `$tableName`.`$patient_idField` = `$tableDataName`.`$patient_idField`
    COLLATE utf8_general_ci
    WHERE `$tableName`.`$login_idField` = $usssName
    ORDER BY `$tableDataName`.id DESC LIMIT 10
) AS descending_select ORDER BY id;

(列名都是可变的并且可能发生冲突(并且不包括 id 本身),这有点尴尬。)

于 2013-01-28T23:38:30.167 回答
1

你能做到这一点吗

select * from (
    SELECT `$tableName`.`$patient_idField` 
         , `$tableDataName`.`$patient_idField` 
         , `$tableDataName`.`$resultField` 
         , `$tableName`.`$login_idField`
         ,`$tableDataName`.id
    FROM `$tableName`
      JOIN `$tableDataName` ON `$tableName`.`$patient_idField` 
                             = `$tableDataName`.`$patient_idField`
    COLLATE utf8_general_ci
    WHERE `$tableName`.`$login_idField` = $usssName
    ORDER BY `$tableDataName`.id DESC LIMIT 10 ) t
order by id

试试这个,我已经编辑以更好地反映你实际在做什么

select  *
from (
    SELECT userlist.patient_id, results.result, userlist.login_id
    FROM userlist
      JOIN results ON userlist.patient_id = results.patient_id
    COLLATE utf8_general_ci
    WHERE userlist.login_id = ####
    ORDER BY results.id DESC
    LIMIT 10 ) temp
order by patient_id
于 2013-01-28T23:37:31.090 回答