我有3個表,我試圖通過內部連接來連接這些表。然而,當我使用count(distinct column_id)
它的mysql通過錯誤是在多個表上的內部連接,計數和明確
SQL語法:檢查
爲正確的語法使用近「(DISTINCT
as_ticket
vehicle_id
)從as_vehicle
INNER JOINas_ticket
我的查詢
SELECT
`as_vehicle`.`make`, `as_vehicle`.`model`, `as_odometer`.`value`
COUNT (DISTINCT `as_ticket`.`vehicle_id`)
FROM `as_vehicle`
INNER JOIN `as_ticket`
ON `as_vehicle`.`vehicle_id` = `as_ticket`.`vehicle_id`
INNER JOIN `as_odometer`
ON `as_odometer`.`vehicle_id` = `as_vehicle`.`vehicle_id`
WHERE `as_ticket`.`vehicle_id` = 7
ORDER BY `as_odometer`.`value`
DESC
Tbl as_vehicle
+------------+-------------+---------+
| vehicle_id |make | model |
+------------+-------------+---------|
| 1 | HYUNDAI | SOLARIS |
| 2 | A638EA15 | ACCENT |
+-------------+------------+---------+
Tbl as_odometer;
+------------+-------+
| vehicle_id | value |
+------------+-------+
| 1 | 10500 |
| 5 | 20000 |
| 1 | 20000 |
+------------+-------+
Tbl service
+-----------+------------+
| ticket_id | vehicle_id |
+-----------+------------+
| 1 | 1 |
| 2 | 1 |
+-----------+------------+
哦,我已經試過了......現在它通過這個錯誤 – 2015-02-09 12:33:36
語法在'DISTINCT' as_ticket'.'vehicle_id'附近使用)FROM'as_vehicle' INNER JOIN'as_ticket – 2015-02-09 12:34:03
'count'有一些不可見的字符'。刪除該部分並在鍵盤上再次寫下它。之後,它爲我工作。 – 2015-02-09 12:38:08