Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm using
productinfo (`productId`, `productName`, `productPrice`, `productSaleprice`, `productImage`, `productLink`, `productColor`, `productSize`, `categoryId`, `sourceProductId`, `sourceId`)
where productinfo is table, And i display products on the basis of productPrice and productSaleprice.
At this moment I fetch all results and calculate everything in PHP like this:
$diff=$productPrice-$productSaleprice;
$result=($diff)/($productPrice/100);
My question is, is it possible to calculate the same things in MySQl without using PHP?
The result should be displayed in DESC Order
I think below SQL useful to you.
select `productId`, `productName`, productPrice, productPrice, productPrice-productSaleprice as diff ,
(productPrice-productSaleprice)/(productPrice/100) as result
from productinfo
where category= 5
order by result desc;
Thank you
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Trying to query db. I need to show all fields, but need to exclude one name that is in the db.
Example:
The db contains column 'marketer' when I try to query it I don't want marketer 'Tommy' but all the others. I have tried tried where clause with all the names and not working.
This is the query you're looking for
SELECT * FROM <table_name> WHERE marketer<>'Tommy';
use the 'where' to add your conditions
SELECT * FROM your_table WHERE marketer!='Tommy'
For your Reference
http://www.w3schools.com/sql/sql_where.asp
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have table called TABLE_1 which has following columns:
id phone_number user_name country state
I want to search with this string " 1, 948583848, akash, usa,calfornia". How do I write a mysql query to get result form above Phone TABLE_1?
Is this the where clause that you want?
where concat_ws(', ', id, phone_number, user_name, country, state) = '1, 948583848, akash, usa,calfornia'
This seems like a very strange requirement. You are better off doing individual comparisons on the columns rather than concatenating the values together.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have this code:
$date=mysql_query("SELECT * FROM players where AdminLevel>='1' ORDER BY AdminLevel,UltReg DESC LIMIT 0,100");
I wanna sort something, and i don't know how to use for more "orders"
You can add additional levels to the ORDER BY statement by adding them separated by commas, as you have done for two levels.
For example:
$date=mysql_query("SELECT * FROM players where AdminLevel>='1' ORDER BY AdminLevel,UltReg DESC, anotherField ASC, yetAnotherField DESC, oneMoreFieldHere LIMIT 0,100");
Additionally, you should be using mysqli_query() instead of mysql_query() as mysql_query() has been deprecated.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a query that is returning a different amount of user_id's each time it's run (based on the number of subscribers).
What I need to do is insert each of these user_id results into separate rows within a table along with a simple message of "new alert" in a separate column.
How could I possibly go about doing this? Would a for each loop work in this situation?
Try this:
INSERT INTO alert_table SELECT user_id, 'new alert' FROM ... WHERE ...
Use your own query, just prepend it with the INSERT INTO alert_table clause.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a mysql database where there is 3 tables 'groupstage', 'quarterfinal,' semifinal. All of these table have a column named 'Date'. Now I want to write a query from where I can get all the fields from those tables with a specific date? what should i write it in php?
To get what you want, you can write a query which join the 3 tables like :
SELECT *
FROM groupstage, quarterfinal, semifinal
WHERE groupstage.date = quarterfinal.date AND quarterfinal.date = semifinal.date
AND date = "YOUR DATE"
In php you should just create a var $query = "My query above"