如何在MySQL的左外连接中有序显示类别
问题描述:
How could I display this query, ordered by qid?
$newcount=$db->get_results("
SELECT s2.qcategory,
s1.id,
count(s1.na) as na_count
FROM (
select distinct `qcategory`
from store
where survey_name='$userID' and
dateone='$dateVal' and
branch='$branch'
) s2
left join store s1
on s1.`qcategory` = s2.`qcategory` and
s1.`na` = '1'
group by 1
order by s1.qid");
如何按qid排序显示此查询? p>
$ newcount = $ db-> get_results(“
SELECT s2.qcategory,
s1.id,
count(s1.na)as na_count
FROM(
从商店中选择不同的`qcategory`
其中survey_name ='$ userID'和
dateone ='$ dateVal'和
branch ='$ branch'
)s2
在s1 .qcategory` = s2 .qcategory上的左连接商店s1
`和
s1 .na` ='1'
按1
顺序分组,由s1.qid“);
code> pre>
div>
答
since the data type is VARCHAR
you need to convert it to numeric, eg
ORDER BY CAST(s1.qid AS SIGNED) ASC
答
u maybe want to order ASC or DESC
try this
ORDER BY s1.qid ASC
or
ORDER BY s1.qid DESC
and why you make GROUP BY 1
??