MYSQL SUM Value [closed] - mysql

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 2 table :
table structure for "kegiatanrenja"
idkegiatan tahun koderekening detail
renja001 2001 1.03.03.04.1 A
renja002 2001 1.03.03.03.2 B
renja003 2001 1.08.08.05.3 C
renja004 2001 1.08.08.05.2 D
table structure for "sumberdana"
idkegiatan nilai kodesumberdana
renja001 100 1
renja002 200 2
renja003 50 1
renja004 100 1
I want to create a query that displays the value of all the columns "nilai" if MID (koderekening, 9,2) the same value, along with the value of another column, where each row in the group by where each row in the group by MID (koderekening, 9,2).
kode rekening nilai_group(SUM Of value the same kode MID(koderekening,9,2)
1.03.03.04 300
1.08.08.05 150
please help, every suggestion will be very appreciated.

SELECT LEFT(koderekeneing,0,10), sum (nilal)
FROM kegiatanrenja k
JOIN sumberdana s ON s.idkegiatan = k.idkegiatan
GROUP BY MID(koderekening,9,2)
UNION
SELECT 'ALL', sum (nilal)
FROM kegiatanrenja k
JOIN sumberdana s ON s.idkegiatan = k.idkegiatan
Please note, this is VERY easy, so if you are asking this sort of question on stack lot, you are going to receive a negative response. Please get yourself a good SQL book and do some studying.

Related

how do I select records that are missing a particular type of row [closed]

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 1 year ago.
Improve this question
I have a payment table. Type 1 is new/first payment. Type 11 is renew payment. So each user should have one record of type 1. But due to bad coding, right now, some records have only renew records. I want to find all the records that are missing the type 1 record. In the example below, it should return user 3.
user type amount
1 1 10
1 11 10
2 1 10
3 11 10
How should I write the query?
One way to find all users in the table that don't have a record of Type 1 is a NOT EXISTS using a subquery, as follows:
SELECT p.[user]
FROM payment p
WHERE NOT EXISTS (
SELECT 1
FROM payment
WHERE `user` = p.[user]
AND type = 1)
Alternatively, this can be done with a LEFT JOIN and only selecting the non-matching rows:
SELECT p.[user]
FROM payment p
LEFT JOIN payment p2
ON p2.[user] = p.[user]
AND p2.type = 1
WHERE p2.[user] IS NULL

SQL Display student record having maximum marks from other table [closed]

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 4 years ago.
Improve this question
student(sID,sNAME,sCLASS);
result(sID,subMARKS);
Actually, in MS-ACCESS, i am trying to this with equi join but getting wrong result. i'm writting my query like
SELECT stud.sID
, stud.sNAME
, stud.sCLASS
, result.sID
FROM student
, result
WHERE(SELECT MAX(subMARKS) FROM result)
It should display Ali record only because he is having maximum marks. but i am getting this kind of output as shown in picture below.
sID sNAME sCLASS
1 Ali BSC
2 Ahmad FSC
3 Asgar ICS
4 Akram BSC
SELECT T1.SID, T1.sname FROM student T1
LEFT JOIN resultT2 ON t1.sid=t2.sid
WHERE t2.submarks = (SELECT Max(submarks) FROM result);

How to calculate with multiple value in SQL [closed]

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
How to dividing field "budget" with multiple value
Look like "SELECT fName, (budget/ 2,3,4) FROM Table"
fName budget
---------------
A 100 >>divide with 2
B 100 >>divide with 4
C 100 >>divide with 6
The result is
fName budget
---------------
A 50
B 25
C 16.67
SELECT fname,CASE WHEN fname ='A' THEN budget/2
WHEN fname ='B' THEN budget/4
WHEN fname ='C' THEN budget/6
END
FROM tableName
Although it's very unclear what you're asking, I guess you may need something like this:
create temporary table and put your desired values in it. then make a cross join to your main table:
SELECT
fName
, Table.budget / tempTable.ColumnName
FROM
Table CROSS JOIN tempTable

count all records columns with value 0 or 1 in mysql/php [closed]

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
Please help me friends. I have attached a screenshot of my table I wish to count all columns with value 0 or 1 where buno="$busno".
Sorry But I don't have any code. I have database table and I don't know how to query at such condition. In the table you can see fields busno with seat A1,A2,A3,A4,B1,B2......N1,N2,N3 and N4. They have only 2 values 1 and 0. 0 for vacant and 1 for booked. I wish to find out how many seats are left (in numbers like 10 0r 20) for a particular busNo. Are you getting my problem?
Get the result row in PHP with the query buno = "$busno", and iterate resultset in php and count the number you want.

How to find rows that has values that exists with criteria 'a' in a table but does not exist with criteria 'b'? [closed]

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 an aggregated table like:
No Field1 Type
12 -1 FR2
12 45 FR1
11 -1 FR2
11 30 FR2
11 20 FR1
Is it possible to select Nos according to types where they possess negative values in Field1 and no other entries with positive values?
Is it possible to find the negation of that selection?
Hence the output should be:
No
11
Explanation:
I am trying to check for people who have failed a list of tests and have not retaken and passed them. Those who never failed as well as those who retook and passed is the result.
In the result output, 12 is not returned because it has negative values for FR2 and no subsequent positive values for FR2.
Thanks.
SELECT No
FROM
( SELECT No, MAX(Field1) AS MaxField1
FROM tableX
GROUP BY No, Type
) AS tmp
GROUP BY No
HAVING MIN(MaxField1) > 0 ;
Tested at SQL-Fiddle
select distinct No from yourtable
group by No,Type
having max(Field1) >0
and min(Field1)<0