SELECT DISTINCT
t1.name as t1_name,
t1.unit as t1_unit,
t1.id_producer_goods AS hi_id_producer_goods,
t2.name as t2_name
FROM Table1 t1
left join Table2 t2 on t1.id_web_site=t2.id_web_site
WHERE t1.id='23'
如何t1.name
在它的查询中计数?
我检查代码:
SELECT DISTINCT
t1.name as t1_name,
count(t1.name) as count,
t1.unit as t1_unit,
t1.id_producer_goods AS hi_id_producer_goods,
t2.name as t2_name
FROM Table1 t1
left join Table2 t2 on t1.id_web_site=t2.id_web_site
WHERE t1.id='23'
但它的代码有错误:
Column 'Table1.name' is invalid in the select list because
it is not contained in either an aggregate function or the GROUP BY clause.
我知道我写得不对,count(t1.name) as count,
但是如何正确计数t1.name
?
PS:查询得到具有唯一行的结果t1.name, t1.unit, t1.id_producer_goods, t2.name
。计数t1.name
应该显示所有计数每个元素t1.name
。