Is there any way to get the if statement to evaluate a query? SELECT if(5>0,'EQ_Type','*') FROM EQUIPMENT; Resulting in: +-----------------------+ | IF(5>0,'EQ_Type','*') | +-----------------------+ | EQ_Type | | EQ_Type | | EQ_Type | | EQ_Type | | EQ_Type | | EQ_Type | | EQ_Type | | EQ_Type | | EQ_Type | +-----------------------+ 9 rows in set (0.00 sec) I would like the above statement to be equivalent to the following: SELECT 'EQ_Type' FROM EQUIPMENT; And produce: +--------------+ | EQ_Type | +--------------+ | ENGINE | | ENGINE | | ENGINE | | TRAILER | | TRAILER | | TRAILER | | WATER TENDER | | WATER TENDER | | WATER TENDER | +--------------+ Thanks for any help
1
A
回答
3
只删除单引号。在这种情况下CASE statements - -
SELECT if(5>0,EQ_Type,'*') FROM EQUIPMENT;
+0
谢谢先生。我是新手,所以我认为这将是明显的。 – 2009-12-14 01:23:22
1
我建议使用ANSI符号,而不是MySQL的特定语法:
SELECT CASE WHEN 5 > 0 THEN t.eq_type ELSE '*' END
FROM EQUIPMENT t
原因是,如果你改变了数据库 - 这种说法不会需要改变工作在Oracle,Postgres,SQL Server等上。
相关问题
- 1. PHP MYSQL if null statement
- 2. jquery if statement issue
- 3. IF statement validate.js
- 4. if statement ambiguity
- 5. svg if statement
- 6. iMacro If Else Statement
- 7. Symfony2 {%if statement%}
- 8. If/Else Statement
- 9. JavaScript if statement scope
- 10. if statement with datatables
- 11. NSArray和“If-statement”
- 12. Long if statement
- 13. Javascript - if statement error
- 14. IF statement == not working
- 15. if statement and mutate
- 16. Mysql select if else和order by statement
- 17. If or If-Else Statement Error
- 18. If-Statement for String/Int
- 19. If Else statement in Fullcalendar
- 20. if statement(banking - credit/debit)
- 21. If-Statement Help in PHP
- 22. If-Else statement with JSF
- 23. If-statement with changing url
- 24. Nestled IF(NOT(ISBLANK))Statement?
- 25. if statement not reading variables
- 26. If/Else Statement Not Evaluating
- 27. If/Else Statement Location - Javascript
- 28. Google Spreadsheet long IF statement?
- 29. MySql select question
- 30. MySQL concat question
Wont 5> 0总是导致'true',因此EQ_Type?我不太了解MySql,所以我可能会误解它。这只是一个人为的例子吗? – GrayWizardx 2009-12-14 01:35:07