Получение MySQL запроса с ключом, где работает ключ.Помоги мне разобраться - PullRequest
0 голосов
/ 09 февраля 2019
SELECT c.name as "Client Name"
     , c.email as "Email"
     , c.phone as "Phone"
     , cnt.name as "Country"
     , c.street as "Street"
     , c.city_id as "City/Suburb"
     , st.name as "State"
     , c.zip_code as "Postcode"
     , "" as "Total Paid"
     , "" as "Total Owed"
     , CASE WHEN c.delete_status = 1 THEN "Not Active" ELSE "Active" END as "Status" 
  FROM customer c 
  LEFT 
  JOIN shipping_address s 
    ON c.id = s.customer_id 
  LEFT 
  JOIN states st 
    ON st.id = c.state_id 
  LEFT 
  JOIN countries cnt 
    ON cnt.id = c.country_id 
  WHEN c.delete_status = 0

Выше мой запрос.И у меня ниже сообщение об ошибке в phpmyadmin, где я не нахожу каких-либо проблем в запросе.

You can see error in screenshot

Ответы [ 2 ]

0 голосов
/ 09 февраля 2019

У вас возникли проблемы, сообщение об ошибке связано с неправильным словом предложения USE, где (а не когда) для условия where

, но вы также неверно используете кавычку
не используйте двойные кавычкидля псевдонима имени столбца используйте при необходимости backtics

  SELECT c.name as `Client Name`
  , c.email as Email
  , c.phone as Phone
  , cnt.name as Country
  , c.street as Street
  , c.city_id as `City/Suburb`
  , st.name as State
  , c.zip_code as Postcode
  , "" as `Total Paid`, "" as `Total Owed`
  , ( CASE WHEN c.delete_status = 1 THEN "Not Active" ELSE "Active" END ) as Status 
  FROM customer c 
  LEFT JOIN shipping_address s ON c.id = s.customer_id 
  LEFT JOIN states st ON st.id = c.state_id 
  LEFT JOIN countries cnt ON cnt.id = c.country_id 
  WHERE  c.delete_status = 0
0 голосов
/ 09 февраля 2019

Измените КОГДА на ГДЕ в запросе

SELECT c.name as "Client Name", c.email as "Email", c.phone as "Phone", cnt.name as "Country", c.street as "Street", c.city_id as "City/Suburb", st.name as "State", c.zip_code as "Postcode", "" as "Total Paid", "" as "Total Owed", ( CASE WHEN c.delete_status = 1 THEN "Not Active" ELSE "Active" END ) as "Status" FROM customer c LEFT JOIN shipping_address s ON c.id = s.customer_id LEFT JOIN states st ON st.id = c.state_id LEFT JOIN countries cnt ON cnt.id = c.country_id WHERE c.delete_status = 0
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...