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 a table called 'list' that is like this:
system item1 exception
------------------------
A John 1
A Sarah 0
A Tim 1
A Blake 0
B Nikki 1
B Rick 0
C Jimbo 1
I am trying to build a query and I'm so terrible at it and I'm stuck. I want to return all rows unconditionally UNLESS system = 'A'. If system = 'A' then only return the rows where exception is true.
Thanks for your time.
What about this?
SELECT * FROM table WHERE system != 'A' OR exception = 1
SQL FIDDLE DEMO
select *
from list
where (system = 'A' and exception = 1)
or system <> 'A'
You can group conditions in the WHERE clause by enclosing each block in ()
http://www.techonthenet.com/sql/and_or.php
Related
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 2 years ago.
Improve this question
MYSQL how to increment column count if different combination row exist
for example if table have
count user certNo
0 a 001
0 b 886
if same user with different certNo comes then i need to increment count by 1,
like
count user certNo
0 a 001
0 b 886
1 a 673
For legacy MySQL version you can use next query:
select
t.*,
count(t1.certNo) as count
from test t
left join test t1 on t1.user = t.user and t1.certNo < t.certNo
group by t.user, t.certNo;
Test it on SQLize.online
You can use row number():
select row_number() over (partition by user order by certNo) - 1 as count,
user, certNo
from t;
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);
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.
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.
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