implementing 2:1 multiplexer with 5 variable equation - boolean-logic

This is my boolean equation: (P+Q)S+(R+T)S' (2^5)
How can I get to a 2:1 multiplexer using its truth table?
I tried to reduce the truth table to a 16 bit table and then to an 8 bit then to 4 then to 2, but I didn't get to any result.

Introduce two auxiliary/intermediate variables:
A := P + Q (A := P or Q)
and
B := R + T (B := R or T)
You multiplexer expression is now
Z := A*S + B*S' (Z := A and S or B and not S)
The truth table:
S A B Z
----------
0 0 0 0
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 1
----------
Truth table in minimized form showing only rows with output 1:
S A B Z
----------
0 X 1 1 'X' = don't care
1 1 X 1
----------

Related

What is meaning of double backslash(column_name\\(1)) in ms access database where clause?

I have some old code which has syntax like this.
SELECT *
FROM Tb
WHERE (column_name\\(1)) mod 2 = 1
Can someone explain the statement column_name\\(1) in where clause.
As is, it is invalid syntax. If it is a string in, say, C#, it may result in:
SELECT *
FROM Tb
WHERE (column_name\(1)) mod 2 = 1
which can be reduced to:
SELECT *
FROM Tb
WHERE column_name mod 2 = 1
*Test for Erik:*
The trick is, that Mod by itself does the integer rounding.
~~~vba
Public Sub TestMod()
Dim Value As Double
Dim Index As Integer
For Index = 0 To 15
Value = Index / 4
Debug.Print Value, Value \ 1, Value Mod 2, (Value \ 1) Mod 2, Round(Value) Mod 2
Next
End Sub
Output:
~~~vba
0 0 0 0 0
0,25 0 0 0 0
0,5 0 0 0 0
0,75 1 1 1 1
1 1 1 1 1
1,25 1 1 1 1
1,5 2 0 0 0
1,75 2 0 0 0
2 2 0 0 0
2,25 2 0 0 0
2,5 2 0 0 0
2,75 3 1 1 1
3 3 1 1 1
3,25 3 1 1 1
3,5 4 0 0 0
3,75 4 0 0 0

Query for one column from database, but display two column for difference condition in table view

Here are my database "Stock", and "Quan":
item model Quantity
-----------------------------
A 2 3
A 3 4
B 3 1
C 3 1
D 2 1
E 2 1
F 3 2
G 2 2
Current code
Select stock.item, stock.model, stock.Quantity as model_2
FROM stock
WHERE stock.item ='2'
CURRENT display:
item model_2
--------------------
A 3
D 1
E 1
G 2
Do any way to display one more column with condition:
WHERE stock.item ='3'
So that I can display as below table?
item model_2 model_3
----------------------------
A 2 4
B 0 1
C 0 1
D 1 0
E 1 0
F 0 2
G 2 0
Thanks!!!!!!!!!!!!
Use the modulus operator along with a CASE expression:
SELECT
item,
CASE WHEN model % 2 = 0 THEN model ELSE 0 END AS even,
CASE WHEN model % 2 = 1 THEN model ELSE 0 END AS odd
FROM abc;

Sql query Where Clause X in Y

I have trouble with where clause
Table
X Y
-- --
1 10
1 15
1 20
0 10
0 20
0 40
0 50
I want to select all X but where X=0 the Y only >20
because all value Y where X=1 is <20
so the result would be
result table
X Y
-- --
1 10
1 15
1 20
0 40
0 50
SELECT * FROM tablename
WHERE (X = 0 AND Y > 20) OR (X = 1 AND Y < 20)
SELECT * FROM TABLENAME
WHERE (X = 1 AND Y<=20) OR (X=0 AND Y>20);

getting data in single query

Say I have the following:
id bill vote
1 x 1
2 y 1
3 y 0
4 z 1
5 x 1
What I want the query to return is:
bill vote(1) vote(0)
x 2 0
y 1 1
z 1 0
vote(1) is count of data (1), same applies to vote(0)
select bill, sum(vote) as vote_1, sum(1-vote) as vote_0
from tablename
group by bill
The first sum is used to sum all 1's. The second one to sum all 0's (1-1 = 0, 1 - 0 = 1!)

Select query which give those rows having two or more than two non-zero values

I have a MySQL table with 8 columns (id,user,a,b,c,d,e,f)
in which I have a list of distinct users with (0 through 9) values in columns like this:
Id User A B C D E F
1 0001 0 1 0 0 0 0
2 0002 0 5 8 4 6 5
3 0003 0 0 0 0 0 5
4 0004 2 6 4 5 4 1
5 0005 1 0 0 0 0 0
6 0006 7 6 5 4 0 9
7 0007 4 0 0 0 0 8]
I want a MySQL select query which gives a list of those users having two or more than two non-zero values.
So the query should return record id (2,4,6,7). Thanks
Here is another way to do so
select *
from t
where
(
(A <> 0 )+
(B <> 0) +
(C <> 0 )+
(D <> 0 )+
(E <> 0 )+
(F <> 0 )
) >= 2
Not equal to operator returns boolean(0/1) value against the criteria and you can sum up the results for each column and eliminate the records according to your criteria
DEMO
Try this.
select user
from (
SELECT *,
CASE WHEN a>0 THEN 1 ELSE 0 END +
CASE WHEN b>0 THEN 1 ELSE 0 END +
CASE WHEN c>0 THEN 1 ELSE 0 END +
CASE WHEN d>0 THEN 1 ELSE 0 END +
CASE WHEN e>0 THEN 1 ELSE 0 END +
CASE WHEN f>0 THEN 1 ELSE 0 END chk
FROM yourtable
) a
where chk>=2