Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I would like to select month(yyyy-mm),opening,debit,credit,closing
from transactions group by month(yyyy-mm);
here is the transactions table
date,debit,credit
Is it posssible in mysql alone with out php?
The easiest way is to use variables, as in:
select `date`, debit, credit, (#bal := credit - debit) as bal
from transaction t cross join
(select #bal := 0) const
order by `date`;
You can then use this for aggregation or whatever you want to do.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 months ago.
Improve this question
I have table like this :
then i want query data like this :
how did to do that?
A subquery with group by should do the job:
select * from <table_name>
where (serial_number, attempt) in (select serial_number, max(attempt) from <table_name> group by serial_number)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have this table:
Well, When I execute this query:
SELECT * FROM users order by rp_bought desc limit 5
I get no errors but, The username, Raed is in the last place as Raed Has the Most Rp_Bought (1300)
Im Wondering Why is this Problem Occurring.
This would occur if rp_bought were stored as a string rather than as a number. In MySQL you can easily fix this by adding 0:
order by rp_bought + 0 desc
The + 0 is an easy way to convert from a string to a number (with no additional errors occurring).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
so let's say I have 5000 rows, I want to select the rows from 2000 to 3000 only, how to do that via a SQL query?
Try this
select * from table limit 2000,1000
limit from,how-many
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Lets say I have the table as follows
Name Firm Salary
Aron X 100
Bill X 200
Clint Y 300
I want to find the firm with maximum number of employees and produce the result
Firm Total
X 2
However here is my problem, The following query never works in MySQL
select firm,max(Number_Of_Employees) as Total from
(select firm,count(*) as Number_Of_Employees from works group by firm)
as temp;
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Could anybody let me know that how can i fetch unique(PKID, Column1,column2) values from my_table in mySql?
You can either use Ozzyberto's way, which should work, or you could use GROUP BY:
SELECT PKID,Column1,Column2
FROM my_table
GROUP BY PKID,Column1,Column2
sqlfiddle demo
You must be looking for the DISTINCT keyword:
http://www.w3schools.com/sql/sql_distinct.asp
You would need the following query:
SELECT DISTINCT PKID, Column1,column2 FROM my_table