数据库查询select o.extra_id,s.School_ID,s.School_Name,s.Country,o.first_name,o.last_name from orders_extra_info o left join schools_master s on o.organisation_name=s.School_Name order by o.extra_id descSchool ID  School Name         School Country    Student First Name Student Last Name
Pending Schools  Pending Schools Pending Schools     xxx                  xxxx
2          mocheng middle school China             xxxx          xxxx
Pending Schools  Pending Schools Pending Schools     xxxx                 xxxx
Pending Schools  Pending Schools Pending Schools     xxxx          xxxx
Pending Schools  Pending Schools Pending Schools     chen          xxxx
Pending Schools  Pending Schools Pending Schools     xxxx          xxxx
得出这么多查询集合,
正常情况是这么排序,,然后界面中还有2个select选择框,一个是各学校的名字,一个是国家然后问题是,,select选择要过滤排序,排序的要求是 先按 School Name 后按 School Country排序, 
比如select选择 school name为mocheng middle school,那么记录中只显示一条记录,其余5条过滤掉,,好像很难啊

解决方案 »

  1.   

    School ID   ————  School Name ————  -   School Country
    null    ———————————     null  ——————-----null
    2------------------------mocheng middle school-----China
    null    ———————————     null  ——————-----null
    null    ———————————     null  ——————-----null
    null    ———————————     null  ——————-----null
    这样看的清晰点
      

  2.   

    1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1select count(*) as total from (select o.extra_id,s.School_ID,s.School_Name,s.Country,o.first_name,o.last_name from orders_extra_info o left join schools_master s on o.organisation_name=s.School_Name
    居然有这种错误,select count(*) 难道不能查询  集合 ???完了,没人搭理了,锋芒太露也不好啊,,换马甲了要
      

  3.   

    select count(*) as total from (select o.extra_id,s.School_ID,s.School_Name,s.Country,o.first_name,o.last_name from orders_extra_info o left join schools_master s on o.organisation_name=s.School_Name->select count(*) as total from (select o.extra_id,s.School_ID,s.School_Name,s.Country,o.first_name,o.last_name from orders_extra_info o left join schools_master s on o.organisation_name=s.School_Name) a
      

  4.   

    select count(*) as total from (select o.extra_id,s.School_ID,s.School_Name,s.Country,o.first_name,o.last_name from orders_extra_info o left join schools_master s on o.organisation_name=s.School_Name你的(并不匹配啊,找不到你的 )
      

  5.   

    我的一整条语句是这么写的$customers_query_raw="select * from (select o.extra_id,s.School_ID,s.School_Name,s.Country,o.first_name,o.last_name from orders_extra_info o left join schools_master s on o.organisation_name=s.School_Name order by o.extra_id desc)as tmp where tmp.School_Name='".$_GET['search_school_name']."'";
    再运行的时候,,运行到select count(*) as total from  这条sql语句的时候报错。。报错提示2楼
      

  6.   

    select count(*) as total from (
      select * from (
    select o.extra_id,s.School_ID,s.School_Name,s.Country,o.first_name,o.last_name from                                                 orders_extra_info o left join schools_master s on o.organisation_name=s.School_Name   order by o.extra_id desc)
    )换个角度说,运行这句话报错,,谁能解释一下错在何处
      

  7.   

    SELECT COUNT(*) AS total FROM (
       SELECT * FROM (
    SELECT o.extra_id,s.School_ID,s.School_Name,s.Country,o.first_name,o.last_name FROM orders_extra_info o LEFT JOIN schools_master s ON o.organisation_name=s.School_Name ORDER BY o.extra_id DESC) a
    ) b
      

  8.   

    select count(*) as total from (
     select * from (
    select o.extra_id,s.School_ID,s.School_Name,s.Country,o.first_name,o.last_name from                                                 orders_extra_info o left join schools_master s on o.organisation_name=s.School_Name   order by o.extra_id desc) t1
    ) t2提问时一定要提问完整的信息,否则别人根本无法准确判断你的问题。 比如你把你相关的表的show ceate table 也贴出的话,别人就可以直接进行测试以确保回复你的语句的正确性。没有你表的信息,则只能手工看个大概。问题说明越详细,回答也会越准确!参见如何提问。(提问的智慧