I am doing column ordering with 4 columns.In big screen, i want it like this.
------- ----------
|a | |b |
------- | |
|c | | |
------- | |
|d | ----------
-------
In small screen, i want to stack in order, a,b,c,d, as shown below.
--------
|a |
--------
|b |
--------
|c |
--------
|d |
--------
Below is my code.
<div class="row">
<div class="col-sm-4"style="color:black;background:yellow">A
</div>
<div class="col-sm-6"style="">
<div class="row">
<div class="col-sm-12 "style="color:white;background:green">B<br>B<br>B<br>B</div>
<div class="col-sm-4 col-sm-pull-8 "style="color:white;background:red">C</div>
<div class="col-sm-12 col-sm-pull-8 "style="color:white;background:blue">D</div>
</div>
</div>
</div>
Related
If I have multiple tables with same columns
table1:
==========
|id | a |
==========
|1 | aa |
|2 | bb |
|3 | cc |
|4 | dd |
==========
table2:
==========
|id | a |
==========
|1 | aa |
|2 | bb |
|3 | cc |
|4 | dd |
==========
table3:
===========
|id | a |
==========
|1 | aaa |
|2 | bbb |
|3 | ccc |
===========
How do I merge the 3 tables so that the output contains all ids in all 3 tables. It uses the last table table3 id contents and if there is id missing like id 4 it uses the previous time id 4 was seen in table so table2.
Final output should be like below:
============
|id | a |
============
|1 | aaa |
|2 | bbb |
|3 | ccc |
|4 | dd |
============
I was thinking joining by full or union but not sure how to format output table to be like above.
finaloutput = \
table3 \
.join(table2, (table3.id == table2.id), "full") \
.join(table1, (table3.id == table1.id), "full")
I think you are looking for the coalesce function that returns the first non null element in its arguments.
In your case, it would go like this:
import pyspark.sql.functions as F
# take table3.a if it exists, otherwise take table2.a if it exists
# and otherwise take table1.a
table3\
.join(table2, ['id'], "full")\
.join(table1, ['id'], "full")\
.select("id", F.coalesce(table3.a, table2.a, table1.a).alias("a"))\
.show()
+---+---+
| id| a|
+---+---+
| 1|aaa|
| 2|bbb|
| 3|ccc|
| 4| dd|
+---+---+
i'm using postgre sql and i want to select data from database like this
------------------------------------
total1 | total2 | total3 | province|
------------------------------------
1 |1 |2 |Maluku |
2 |3 |4 |Aceh |
4 |7 |2 |Riau |
------------------------------------
but my result from query like this
------------------------------------
total1 | total2 | total3 | province|
------------------------------------
1 |1 |2 |Maluku |
1 |1 |2 |Aceh |
1 |1 |2 |Riau |
------------------------------------
my query
SELECT (SELECT COALESCE(COUNT(id),0) FROM vent) as total1,
(SELECT COALESCE(COUNT(id),0) FROM ventWHERE jenis='Vent-I') as total2,
(SELECT COALESCE(COUNT(id),0) FROM ventWHERE status='Terpakai') as total3,
b.provinsi as province
FROM public."admin_provinsi" as b LEFT JOIN
public."rs" as a
on a.provno = b.idprov
GROUP BY b.provinsi, b.idprov
ORDER BY total1 DESC
how to make result of the query like that?
my scheme database
table vent
|id|jenis |id_rs|status |
--------------------------
|1 |vent-i|1 |Terpakai|
|2 |vent-i|2 |Tidak |
table rs
|gid|name |provno|
-----------------
|1 |rs depok | 1 |
|1 |rs depok2| 1 |
table admin_provinsi
|idprov|nama |
---------------
|1 |Maluku|
|2 |Aceh |
|3 |Riau |
I have a data set with 4 columns and want to count the number of times that the value in column 2 was equal to the value in one of the rows in column 0 and also the number of times that the value in column 3 was equal to the value in one of the rows in column 0. Also I want to filter the data based on the value in column 1.
Here is an example:
|0 |1 |2 |3 |
-----------------------------------------
|a |post |b |c |
|x |share |a |d |
|b |post |a |l |
|d |post |N/A |a |
-----------------------------------------
the result should look like this:
|0 |1 |2 |3 |4 |5 |
-------------------------------------------------------------
|a |post |b |c |2 |1 |
|b |post |a |l |1 |0 |
|d |post |N/A |a |0 |1 |
-------------------------------------------------------------
Therefore I need to add two columns to my data set. My initial thought is that I can use nested query. Here's my code:
SELECT *
FROM
(
select t.*,
(select count(*) from
(
select t.*,
(select count(*) from tab where [2] = t.[0]) [4]
from tab t
)
where [3] = t.[0]) [5]
from tab t
)
WHERE [1] = 'post'
but the the result of my query does not return column 4. Can you help me figure out the problem with my code?
Your query contains almost the correct code:
select
t.*,
(select count(*) from tab where [2] = t.[0]) [4],
(select count(*) from tab where [3] = t.[0]) [5]
from tab t
where t.[1] = 'post'
See the demo.
Results:
| 0 | 1 | 2 | 3 | 4 | 5 |
| --- | ---- | --- | --- | --- | --- |
| a | post | b | c | 2 | 1 |
| b | post | a | l | 1 | 0 |
| d | post | N/A | a | 0 | 1 |
I have table X
with 2 columns : ID , name
I need to select only the names with more than 1 ID (and count how much ID those name has)
table X
|namme|ID |
------------
|A |1 |
------------
|A |2 |
------------
|B |1 |
------------
|C |1 |
------------
|C |4 |
------------
|C |7 |
------------
from the table bellow the answer will be like:
|namme|ID Count|
----------------
|A |2 |
----------------
|C |3 |
----------------
name A has 2 IDs
name C has 3 IDs
Try, like:
SELECT Name
,COUNT(ID)
FROM Xtable
GROUP BY Name
HAVING COUNT(ID) > 1
use aggregate function count()
select name,count(*) as cnt from table group by name
having count(*)>1
I have the following data:
Input:
----------------------------
| Id | Value|
----------------------------
| 1 |A |
| 1 |B |
| 2 |C |
| 2 |D |
| 2 |E |
| 3 |F |
----------------------------
I need to convert the results to the following:
Output (Count is based on Id)
----------------------------
| Id | Value| Count|
----------------------------
| 1 |A | 2 |
| 1 |B | 2 |
| 2 |C | 3 |
| 2 |D | 3 |
| 2 |E | 3 |
| 3 |F | 1 |
----------------------------
I am using SQL server 2008. Is it possible to write a query to do this?
If yes could anyone help me provide a SQL to obtain the above output from the input data I gave.
You are looking for COUNT OVER:
select id, value, count(*) over (partition by id)
from mytable
order by id, value;