我该怎么做:
$query = "SELECT a,b FROM c ORDER BY a";
$query1 = "SELECT a,b FROM '".$query."' WHERE a='".$number."'";
非常感谢
REAL CASE
$query2 = "SELECT numero,spartenza,sarrivo,opartenza,oarrivo FROM treni ORDER BY opartenza";
$query1 = "SELECT spartenza,sarrivo,opartenza,oarrivo,TIMEDIFF(oarrivo,opartenza) FROM (".$query2.") AS 'ordinata' WHERE numero = '".$id_treno."' ORDER BY opartenza";
答案 0 :(得分:2)
用括号括起来:
$query1 = "SELECT a,b FROM (".$query.") AS `alias` WHERE a='".$number."'";
像这样的子查询需要别名。
REAL CASE
$ query =“SELECT spartenza,sarrivo,opartenza,oarrivo,TIMEDIFF(oarrivo,opartenza)FROM treni WHERE numero ='”。$ id_treno。“'ORDER BY opartenza”;
您根本不需要子查询。您可以ORDER BY
您未选择的列。但有一个建议是将TIMEDIFF
函数设为别名,以便更容易检索。
$query = "SELECT spartenza,sarrivo,opartenza,oarrivo,TIMEDIFF(oarrivo,opartenza) AS `timediff_alias` FROM treni WHERE numero = '".$id_treno."' ORDER BY opartenza";